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

import typing
from ..core.client_wrapper import SyncClientWrapper
from ..types.metadata import Metadata
from ..core.request_options import RequestOptions
from ..types.evaluation_set_response import EvaluationSetResponse
from ..core.serialization import convert_and_respect_annotation_metadata
from ..core.pydantic_utilities import parse_obj_as
from ..errors.method_not_allowed_error import MethodNotAllowedError
from json.decoder import JSONDecodeError
from ..core.api_error import ApiError
from ..core.jsonable_encoder import jsonable_encoder
from ..core.client_wrapper import AsyncClientWrapper

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


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

    def create_evaluation_set(
        self,
        *,
        name: str,
        description: str,
        scheduler: typing.Optional[str] = OMIT,
        metadata: typing.Optional[Metadata] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EvaluationSetResponse:
        """
        Add a new evaluation set

        Parameters
        ----------
        name : str
            Name of the evaluation set

        description : str
            Description of the evaluation set

        scheduler : typing.Optional[str]
            Scheduler of the evaluation set

        metadata : typing.Optional[Metadata]

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

        Returns
        -------
        EvaluationSetResponse
            Successful operation

        Examples
        --------
        from NeuralTrust import NeuralTrustApi

        client = NeuralTrustApi(
            api_key="YOUR_API_KEY",
        )
        client.evaluation_set.create_evaluation_set(
            name="name",
            description="description",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            "evaluation-set",
            method="POST",
            json={
                "name": name,
                "description": description,
                "scheduler": scheduler,
                "metadata": convert_and_respect_annotation_metadata(
                    object_=metadata, annotation=Metadata, direction="write"
                ),
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    EvaluationSetResponse,
                    parse_obj_as(
                        type_=EvaluationSetResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 405:
                raise MethodNotAllowedError(
                    typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # 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_evaluation_set(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> EvaluationSetResponse:
        """
        Get an evaluation set

        Parameters
        ----------
        id : str
            ID of the evaluation set to retrieve

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

        Returns
        -------
        EvaluationSetResponse
            Successful operation

        Examples
        --------
        from NeuralTrust import NeuralTrustApi

        client = NeuralTrustApi(
            api_key="YOUR_API_KEY",
        )
        client.evaluation_set.get_evaluation_set(
            id="id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"evaluation-set/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    EvaluationSetResponse,
                    parse_obj_as(
                        type_=EvaluationSetResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 405:
                raise MethodNotAllowedError(
                    typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # 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 update_evaluation_set(
        self,
        id: str,
        *,
        name: str,
        description: str,
        scheduler: typing.Optional[str] = OMIT,
        metadata: typing.Optional[Metadata] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EvaluationSetResponse:
        """
        Update an evaluation set

        Parameters
        ----------
        id : str
            ID of the evaluation set to update

        name : str
            Name of the evaluation set

        description : str
            Description of the evaluation set

        scheduler : typing.Optional[str]
            Scheduler of the evaluation set

        metadata : typing.Optional[Metadata]

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

        Returns
        -------
        EvaluationSetResponse
            Successful operation

        Examples
        --------
        from NeuralTrust import NeuralTrustApi

        client = NeuralTrustApi(
            api_key="YOUR_API_KEY",
        )
        client.evaluation_set.update_evaluation_set(
            id="id",
            name="name",
            description="description",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"evaluation-set/{jsonable_encoder(id)}",
            method="PUT",
            json={
                "name": name,
                "description": description,
                "scheduler": scheduler,
                "metadata": convert_and_respect_annotation_metadata(
                    object_=metadata, annotation=Metadata, direction="write"
                ),
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    EvaluationSetResponse,
                    parse_obj_as(
                        type_=EvaluationSetResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 405:
                raise MethodNotAllowedError(
                    typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # 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 run_evaluation_set(
        self,
        id: str,
        *,
        evaluation_set_run_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Run an evaluation set

        Parameters
        ----------
        id : str
            ID of the evaluation set to run

        evaluation_set_run_id : typing.Optional[str]
            ID of the evaluation set to run

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

        Returns
        -------
        None

        Examples
        --------
        from NeuralTrust import NeuralTrustApi

        client = NeuralTrustApi(
            api_key="YOUR_API_KEY",
        )
        client.evaluation_set.run_evaluation_set(
            id="id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"evaluation-set/{jsonable_encoder(id)}/run",
            method="POST",
            json={
                "id": evaluation_set_run_id,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return
            _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 AsyncEvaluationSetClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def create_evaluation_set(
        self,
        *,
        name: str,
        description: str,
        scheduler: typing.Optional[str] = OMIT,
        metadata: typing.Optional[Metadata] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EvaluationSetResponse:
        """
        Add a new evaluation set

        Parameters
        ----------
        name : str
            Name of the evaluation set

        description : str
            Description of the evaluation set

        scheduler : typing.Optional[str]
            Scheduler of the evaluation set

        metadata : typing.Optional[Metadata]

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

        Returns
        -------
        EvaluationSetResponse
            Successful operation

        Examples
        --------
        import asyncio

        from NeuralTrust import AsyncNeuralTrustApi

        client = AsyncNeuralTrustApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.evaluation_set.create_evaluation_set(
                name="name",
                description="description",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "evaluation-set",
            method="POST",
            json={
                "name": name,
                "description": description,
                "scheduler": scheduler,
                "metadata": convert_and_respect_annotation_metadata(
                    object_=metadata, annotation=Metadata, direction="write"
                ),
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    EvaluationSetResponse,
                    parse_obj_as(
                        type_=EvaluationSetResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 405:
                raise MethodNotAllowedError(
                    typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # 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_evaluation_set(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> EvaluationSetResponse:
        """
        Get an evaluation set

        Parameters
        ----------
        id : str
            ID of the evaluation set to retrieve

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

        Returns
        -------
        EvaluationSetResponse
            Successful operation

        Examples
        --------
        import asyncio

        from NeuralTrust import AsyncNeuralTrustApi

        client = AsyncNeuralTrustApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.evaluation_set.get_evaluation_set(
                id="id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"evaluation-set/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    EvaluationSetResponse,
                    parse_obj_as(
                        type_=EvaluationSetResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 405:
                raise MethodNotAllowedError(
                    typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # 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 update_evaluation_set(
        self,
        id: str,
        *,
        name: str,
        description: str,
        scheduler: typing.Optional[str] = OMIT,
        metadata: typing.Optional[Metadata] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EvaluationSetResponse:
        """
        Update an evaluation set

        Parameters
        ----------
        id : str
            ID of the evaluation set to update

        name : str
            Name of the evaluation set

        description : str
            Description of the evaluation set

        scheduler : typing.Optional[str]
            Scheduler of the evaluation set

        metadata : typing.Optional[Metadata]

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

        Returns
        -------
        EvaluationSetResponse
            Successful operation

        Examples
        --------
        import asyncio

        from NeuralTrust import AsyncNeuralTrustApi

        client = AsyncNeuralTrustApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.evaluation_set.update_evaluation_set(
                id="id",
                name="name",
                description="description",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"evaluation-set/{jsonable_encoder(id)}",
            method="PUT",
            json={
                "name": name,
                "description": description,
                "scheduler": scheduler,
                "metadata": convert_and_respect_annotation_metadata(
                    object_=metadata, annotation=Metadata, direction="write"
                ),
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    EvaluationSetResponse,
                    parse_obj_as(
                        type_=EvaluationSetResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 405:
                raise MethodNotAllowedError(
                    typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # 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 run_evaluation_set(
        self,
        id: str,
        *,
        evaluation_set_run_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Run an evaluation set

        Parameters
        ----------
        id : str
            ID of the evaluation set to run

        evaluation_set_run_id : typing.Optional[str]
            ID of the evaluation set to run

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from NeuralTrust import AsyncNeuralTrustApi

        client = AsyncNeuralTrustApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.evaluation_set.run_evaluation_set(
                id="id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"evaluation-set/{jsonable_encoder(id)}/run",
            method="POST",
            json={
                "id": evaluation_set_run_id,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return
            _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)
