# 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.key_indicators import KeyIndicators
from ...core.jsonable_encoder import jsonable_encoder
from ...core.pydantic_utilities import parse_obj_as
from json.decoder import JSONDecodeError
from ...core.api_error import ApiError
from ...types.key_indicator_value import KeyIndicatorValue
from ...core.client_wrapper import AsyncClientWrapper


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

    def list(self, pk: int, *, request_options: typing.Optional[RequestOptions] = None) -> KeyIndicators:
        """
        Get key indicators for the Prompt dashboard.

        Parameters
        ----------
        pk : int
            Inference run ID

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

        Returns
        -------
        KeyIndicators


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

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.prompts.indicators.list(
            pk=1,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/inference-runs/{jsonable_encoder(pk)}/indicators",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    KeyIndicators,
                    parse_obj_as(
                        type_=KeyIndicators,  # 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)

    def get(
        self, indicator_key: str, pk: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> KeyIndicatorValue:
        """
        Get a specific key indicator for the Prompt dashboard.

        Parameters
        ----------
        indicator_key : str
            Key of the indicator

        pk : int
            Inference run ID

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

        Returns
        -------
        KeyIndicatorValue


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

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.prompts.indicators.get(
            indicator_key="indicator_key",
            pk=1,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/inference-runs/{jsonable_encoder(pk)}/indicators/{jsonable_encoder(indicator_key)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    KeyIndicatorValue,
                    parse_obj_as(
                        type_=KeyIndicatorValue,  # 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 AsyncIndicatorsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list(self, pk: int, *, request_options: typing.Optional[RequestOptions] = None) -> KeyIndicators:
        """
        Get key indicators for the Prompt dashboard.

        Parameters
        ----------
        pk : int
            Inference run ID

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

        Returns
        -------
        KeyIndicators


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.prompts.indicators.list(
                pk=1,
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/inference-runs/{jsonable_encoder(pk)}/indicators",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    KeyIndicators,
                    parse_obj_as(
                        type_=KeyIndicators,  # 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)

    async def get(
        self, indicator_key: str, pk: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> KeyIndicatorValue:
        """
        Get a specific key indicator for the Prompt dashboard.

        Parameters
        ----------
        indicator_key : str
            Key of the indicator

        pk : int
            Inference run ID

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

        Returns
        -------
        KeyIndicatorValue


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.prompts.indicators.get(
                indicator_key="indicator_key",
                pk=1,
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/inference-runs/{jsonable_encoder(pk)}/indicators/{jsonable_encoder(indicator_key)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    KeyIndicatorValue,
                    parse_obj_as(
                        type_=KeyIndicatorValue,  # 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)
