<?php

namespace Api\PhpServices\UserInfo;


use Api\PhpUtils\Common\TimeOut;
use Api\PhpUtils\Http\Request;
use App\Exception\custom\CodeSpecialException;

class User
{
    /**
     * 获取用户信息
     */
    public function info($userid){
        $url = config("interface", "service.userinfo.get");
        if(!$url){
            throw new CodeSpecialException("failed");
        }

        $params = ["userid"=>$userid];

        $res = (new TimeOut())->runGet($url, $params);

        if(!$res){
            throw new CodeSpecialException("timeout");
        }

        return $res;
    }


    /**
     * 修改用户昵称
     */
    public function modifyNickname($userid, $nickname, $appid, $partner, $key){
        $url = config("interface", "service.userinfo.modify_nickname");
        if(!$url){
            throw new CodeSpecialException("failed");
        }

        $params = [
            "userid"    => $userid,
            "nickname"  => $nickname,
            "appid"     => $appid,
            "partner"   => $partner,
            "key"       => $key,
        ];

        $res = (new TimeOut())->runGet($url, $params);

        if(!$res){
            throw new CodeSpecialException("timeout");
        }

        return $res;
    }


    /**
     * 修改用户头像
     */
    public function modifyProfile($userid, $profile, $appid, $partner, $key){
        $url = config("interface", "service.userinfo.modify_profile");
        if(!$url){
            throw new CodeSpecialException("failed");
        }

        $params = [
            "userid"    => $userid,
            "profile"  => $profile,
            "appid"     => $appid,
            "partner"   => $partner,
            "key"       => $key,
        ];

        $res = (new TimeOut())->runGet($url, $params);

        if(!$res){
            throw new CodeSpecialException("timeout");
        }
        return $res;
    }
}