<?php  namespace Client\Request;

class User extends Base {

    private $authenticated;
    public $uid;
    public $ulogin;
    public $ufull_name;
    public $uemail;
    public $uavatar_url;
    public $uusername;

    public function __construct(string $api_url, string $api_token, string $user = "") {
        $this->ulogin = (strlen($user) == 0 || $user == "me" ? "me" : $user);
        $this->authenticated = $this->ulogin == "me";
        parent::__construct($api_url, $api_token);
    }

    protected function set_scope(string $method) {
        switch($method) {
        default:
            $this->scope = ($this->ulogin == "me" ? "/user" : "/users/" . $this->ulogin);
        }
    }

    public function authenticated() {
        return $this->authenticated;
    }

    public function repos() {
        return new Repos($this->url, $this->token, $this);
    }

    public function repo(string $name) {
        return (new Repo($this->url, $this->token, $this, $name))->load();
    }

    protected function json_set_property($obj) {
        foreach ($obj as $key => $value) {
            $key = 'u' . $key;
            if (property_exists($this, $key))
                $this->{$key} = $value;
        }
    }
}

?>