# 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.testset_response import TestsetResponse
from ..core.jsonable_encoder import jsonable_encoder
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.client_wrapper import AsyncClientWrapper


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

    def create_testset(
        self, name: str = None, type: str = None, evaluation_set_id: str = None, knowledge_base_id: str = None, num_questions: int = None, request_options: typing.Optional[RequestOptions] = None
    ) -> TestsetResponse:
        """
        Create a testset

        Parameters
        ----------
        name : str
            Name of the testset

        type : str
            Type of the testset

        evaluation_set_id : str
            ID of the evaluation set

        knowledge_base_id : str
            ID of the knowledge base

        num_questions : int
            Number of questions

        Returns
        -------
        TestsetResponse
            Successful operation

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

        client = NeuralTrustApi(
            api_key="YOUR_API_KEY",
        )
        client.testset.create_testset(
            name="Testset 1",
            evaluation_set_id="evaluation_set_id",
            knowledge_base_id="knowledge_base_id",
            num_questions=10,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            "testset",
            method="POST",
            json={
                "name": name,
                "type": type,
                "evaluation_set_id": evaluation_set_id,
                "knowledge_base_id": knowledge_base_id,
                "num_questions": num_questions,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    TestsetResponse,
                    parse_obj_as(
                        type_=TestsetResponse,  # 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_testset(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> TestsetResponse:
        """
        Get a testset

        Parameters
        ----------
        id : str
            ID of the testset to retrieve

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

        Returns
        -------
        TestsetResponse
            Successful operation

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

        client = NeuralTrustApi(
            api_key="YOUR_API_KEY",
        )
        client.testset.get_testset(
            id="id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"testset/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    TestsetResponse,
                    parse_obj_as(
                        type_=TestsetResponse,  # 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 delete_testset(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete a testset

        Parameters
        ----------
        id : str
            ID of the testset to delete

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

        Returns
        -------
        None

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

        client = NeuralTrustApi(
            api_key="YOUR_API_KEY",
        )
        client.testset.delete_testset(
            id="id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"testset/{jsonable_encoder(id)}",
            method="DELETE",
            request_options=request_options,
        )
        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 AsyncTestsetClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def get_testset(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> TestsetResponse:
        """
        Get a testset

        Parameters
        ----------
        id : str
            ID of the testset to retrieve

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

        Returns
        -------
        TestsetResponse
            Successful operation

        Examples
        --------
        import asyncio

        from NeuralTrust import AsyncNeuralTrustApi

        client = AsyncNeuralTrustApi(
            api_key="YOUR_API_KEY",
        )


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


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"testset/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    TestsetResponse,
                    parse_obj_as(
                        type_=TestsetResponse,  # 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 delete_testset(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete a testset

        Parameters
        ----------
        id : str
            ID of the testset to delete

        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.testset.delete_testset(
                id="id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"testset/{jsonable_encoder(id)}",
            method="DELETE",
            request_options=request_options,
        )
        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)
