# This file was auto-generated by Fern from our API Definition.

from ...core.client_wrapper import SyncClientWrapper
import typing
from ...core.request_options import RequestOptions
from .types.stats_iaa_response import StatsIaaResponse
from ...core.jsonable_encoder import jsonable_encoder
from ...core.unchecked_base_model import construct_type
from json.decoder import JSONDecodeError
from ...core.api_error import ApiError
from ...core.client_wrapper import AsyncClientWrapper


class StatsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def iaa(
        self,
        id: int,
        *,
        expand: typing.Optional[str] = None,
        per_label: typing.Optional[bool] = None,
        std: typing.Optional[bool] = None,
        task: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> StatsIaaResponse:
        """
        Get Inter-Annotator Agreement (IAA) matrix for a project, showing agreement between all annotators.

        Parameters
        ----------
        id : int

        expand : typing.Optional[str]
            Comma-separated list of fields to expand

        per_label : typing.Optional[bool]
            Calculate IAA per label

        std : typing.Optional[bool]
            Include standard deviation in results

        task : typing.Optional[str]
            Comma-separated list of task IDs to filter by

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        StatsIaaResponse
            Inter-Annotator Agreement matrix

        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.projects.stats.iaa(
            id=1,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/stats/IAA",
            method="GET",
            params={
                "expand": expand,
                "per_label": per_label,
                "std": std,
                "task": task,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    StatsIaaResponse,
                    construct_type(
                        type_=StatsIaaResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)


class AsyncStatsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def iaa(
        self,
        id: int,
        *,
        expand: typing.Optional[str] = None,
        per_label: typing.Optional[bool] = None,
        std: typing.Optional[bool] = None,
        task: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> StatsIaaResponse:
        """
        Get Inter-Annotator Agreement (IAA) matrix for a project, showing agreement between all annotators.

        Parameters
        ----------
        id : int

        expand : typing.Optional[str]
            Comma-separated list of fields to expand

        per_label : typing.Optional[bool]
            Calculate IAA per label

        std : typing.Optional[bool]
            Include standard deviation in results

        task : typing.Optional[str]
            Comma-separated list of task IDs to filter by

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        StatsIaaResponse
            Inter-Annotator Agreement matrix

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.projects.stats.iaa(
                id=1,
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/projects/{jsonable_encoder(id)}/stats/IAA",
            method="GET",
            params={
                "expand": expand,
                "per_label": per_label,
                "std": std,
                "task": task,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    StatsIaaResponse,
                    construct_type(
                        type_=StatsIaaResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)
