<?php

namespace app;

// 应用请求对象类
use app\http\HttpAuth;
use app\http\HttpClient;
use think\helper\Macroable;

/**
 * @method static HttpClient getClient() 获取客户端信息
 */
class Request extends \think\Request
{
    use Macroable;

    /**
     * @var string
     */
    public string $contextId = '';
    /**
     * @var HttpAuth
     */
    private readonly HttpAuth $auth;

    /**
     * 设置Auth
     * @param HttpAuth $auth
     * @return Request
     */
    public function setAuth(HttpAuth $auth): self
    {
        $this->auth = $auth;
        return $this;
    }

    public function getAuth(): ?HttpAuth
    {
//        var_dump($this->auth);
        return $this->auth ?? null;
    }


    public function getBrowser(): string
    {
        return get_agent_browser($this->server('HTTP_USER_AGENT'));
    }

    public function getDevice(): string
    {
        return get_agent_device($this->server('HTTP_USER_AGENT'));
    }

    public function getOs(): string
    {
        return get_agent_os($this->server('HTTP_USER_AGENT'));
    }

}
