from __future__ import annotations

from typing import Any

from .._types import DialectDetectResponse


class Dialects:
    """Sync dialects: client.dialects.detect(...)"""

    def __init__(self, client: object) -> None:
        self._client = client

    def detect(self, *, text: str, **kwargs: Any) -> DialectDetectResponse:
        payload: dict[str, Any] = {"text": text, **kwargs}

        resp = self._client._http.post(  # type: ignore[attr-defined]
            self._client._build_url("/v1/dialects/detect"),  # type: ignore[attr-defined]
            json=payload,
            headers=self._client._headers,  # type: ignore[attr-defined]
            timeout=self._client.timeout,  # type: ignore[attr-defined]
        )
        self._client._raise_for_status(resp)  # type: ignore[attr-defined]
        return DialectDetectResponse(**resp.json())


class AsyncDialects:
    """Async dialects: client.dialects.detect(...)"""

    def __init__(self, client: object) -> None:
        self._client = client

    async def detect(self, *, text: str, **kwargs: Any) -> DialectDetectResponse:
        payload: dict[str, Any] = {"text": text, **kwargs}

        resp = await self._client._http.post(  # type: ignore[attr-defined]
            self._client._build_url("/v1/dialects/detect"),  # type: ignore[attr-defined]
            json=payload,
            headers=self._client._headers,  # type: ignore[attr-defined]
            timeout=self._client.timeout,  # type: ignore[attr-defined]
        )
        self._client._raise_for_status(resp)  # type: ignore[attr-defined]
        return DialectDetectResponse(**resp.json())
