import os
from typing import Self

import httpx


class RequestClient:
    _client: httpx.Client = None

    def __new__(cls) -> Self:
        if cls._client is None:
            url = os.environ.get("DRIVE_HOST_URL")
            if url is None:
                url = "https://drive.stnicolay.ru"
            cls._client = httpx.Client(base_url=url)
        return super().__new__(cls)

    @classmethod
    def set_token(cls, token: str):
        cls._client.headers = {"Authorization": f"Bearer {token}"}

    @classmethod
    def delete_token(cls):
        cls._client.headers = {}

    @property
    def client(self) -> httpx.Client:
        return self._client
