from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Protocol

import httpx


class Transport(Protocol):
    def request(
        self,
        method: str,
        url: str,
        *,
        headers: dict[str, str] | None = None,
        params: dict[str, Any] | None = None,
        json: Any | None = None,
        data: Any | None = None,
    ) -> httpx.Response: ...

    def close(self) -> None: ...


@dataclass
class HttpxSyncTransport:
    client: httpx.Client

    def request(
        self,
        method: str,
        url: str,
        *,
        headers: dict[str, str] | None = None,
        params: dict[str, Any] | None = None,
        json: Any | None = None,
        data: Any | None = None,
    ) -> httpx.Response:
        return self.client.request(
            method,
            url,
            headers=headers,
            params=params,
            json=json,
            data=data,
        )

    def close(self) -> None:
        self.client.close()
