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

from __future__ import annotations

import typing

from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ...core.request_options import RequestOptions
from ...types.create_agent_test_response_model import CreateAgentTestResponseModel
from ...types.get_tests_page_response_model import GetTestsPageResponseModel
from ...types.get_tests_summaries_by_ids_response_model import GetTestsSummariesByIdsResponseModel
from ...types.test_sharing_mode import TestSharingMode
from ...types.test_type import TestType
from .raw_client import AsyncRawTestsClient, RawTestsClient
from .types.tests_create_request_body import TestsCreateRequestBody
from .types.tests_get_response import TestsGetResponse
from .types.tests_list_request_sort_mode import TestsListRequestSortMode
from .types.tests_update_request_body import TestsUpdateRequestBody
from .types.tests_update_response import TestsUpdateResponse

if typing.TYPE_CHECKING:
    from .folders.client import AsyncFoldersClient, FoldersClient
    from .invocations.client import AsyncInvocationsClient, InvocationsClient
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class TestsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawTestsClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._folders: typing.Optional[FoldersClient] = None
        self._invocations: typing.Optional[InvocationsClient] = None

    @property
    def with_raw_response(self) -> RawTestsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawTestsClient
        """
        return self._raw_client

    def create(
        self, *, request: TestsCreateRequestBody, request_options: typing.Optional[RequestOptions] = None
    ) -> CreateAgentTestResponseModel:
        """
        Creates a new agent response test.

        Parameters
        ----------
        request : TestsCreateRequestBody

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

        Returns
        -------
        CreateAgentTestResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs
        from elevenlabs.conversational_ai.tests import TestsCreateRequestBody_Llm

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.tests.create(
            request=TestsCreateRequestBody_Llm(
                name="name",
            ),
        )
        """
        _response = self._raw_client.create(request=request, request_options=request_options)
        return _response.data

    def move(
        self,
        *,
        entity_ids: typing.Sequence[str],
        move_to: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Moves multiple tests or folders from one folder to another.

        Parameters
        ----------
        entity_ids : typing.Sequence[str]
            The IDs of tests or folders to move.

        move_to : typing.Optional[str]
            The folder to move the entities to. If not set, the entities will be moved to the root folder.

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

        Returns
        -------
        typing.Any
            Tests or folders successfully moved to another folder

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.tests.move(
            entity_ids=["entity_ids"],
        )
        """
        _response = self._raw_client.move(entity_ids=entity_ids, move_to=move_to, request_options=request_options)
        return _response.data

    def get(self, test_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> TestsGetResponse:
        """
        Gets an agent response test by ID.

        Parameters
        ----------
        test_id : str
            The id of a chat response test. This is returned on test creation.

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

        Returns
        -------
        TestsGetResponse
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.tests.get(
            test_id="TeaqRRdTcIfIu2i7BYfT",
        )
        """
        _response = self._raw_client.get(test_id, request_options=request_options)
        return _response.data

    def update(
        self, test_id: str, *, request: TestsUpdateRequestBody, request_options: typing.Optional[RequestOptions] = None
    ) -> TestsUpdateResponse:
        """
        Updates an agent response test by ID.

        Parameters
        ----------
        test_id : str
            The id of a chat response test. This is returned on test creation.

        request : TestsUpdateRequestBody

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

        Returns
        -------
        TestsUpdateResponse
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs
        from elevenlabs.conversational_ai.tests import TestsUpdateRequestBody_Llm

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.tests.update(
            test_id="TeaqRRdTcIfIu2i7BYfT",
            request=TestsUpdateRequestBody_Llm(
                name="name",
            ),
        )
        """
        _response = self._raw_client.update(test_id, request=request, request_options=request_options)
        return _response.data

    def delete(self, test_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Any:
        """
        Deletes an agent response test by ID.

        Parameters
        ----------
        test_id : str
            The id of a chat response test. This is returned on test creation.

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

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.tests.delete(
            test_id="TeaqRRdTcIfIu2i7BYfT",
        )
        """
        _response = self._raw_client.delete(test_id, request_options=request_options)
        return _response.data

    def summaries(
        self, *, test_ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> GetTestsSummariesByIdsResponseModel:
        """
        Gets agent response test summaries for the requested test IDs.

        Parameters
        ----------
        test_ids : typing.Sequence[str]
            List of test IDs to fetch. No duplicates allowed. Prefer at most 1000 IDs per request.

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

        Returns
        -------
        GetTestsSummariesByIdsResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.tests.summaries(
            test_ids=["test_id_1", "test_id_2"],
        )
        """
        _response = self._raw_client.summaries(test_ids=test_ids, request_options=request_options)
        return _response.data

    def list(
        self,
        *,
        cursor: typing.Optional[str] = None,
        page_size: typing.Optional[int] = None,
        search: typing.Optional[str] = None,
        parent_folder_id: typing.Optional[str] = None,
        types: typing.Optional[typing.Union[TestType, typing.Sequence[TestType]]] = None,
        include_folders: typing.Optional[bool] = None,
        sort_mode: typing.Optional[TestsListRequestSortMode] = None,
        sharing_mode: typing.Optional[TestSharingMode] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetTestsPageResponseModel:
        """
        Lists all agent response tests with pagination support and optional search filtering.

        Parameters
        ----------
        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

        page_size : typing.Optional[int]
            How many Tests to return at maximum. Can not exceed 100, defaults to 30.

        search : typing.Optional[str]
            Search query to filter tests by name.

        parent_folder_id : typing.Optional[str]
            Filter by parent folder ID. Use 'root' to get items in the root folder.

        types : typing.Optional[typing.Union[TestType, typing.Sequence[TestType]]]
            If present, the endpoint will return only tests/folders of the given types.

        include_folders : typing.Optional[bool]
            Deprecated. Use the `types` query param and include `folder` instead.

        sort_mode : typing.Optional[TestsListRequestSortMode]
            Sort mode for listing tests. Use 'folders_first' to place folders before tests.

        sharing_mode : typing.Optional[TestSharingMode]
            Filter test visibility. Use `shared_with_me` to return only tests/folders shared with the current user that they did not create.

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

        Returns
        -------
        GetTestsPageResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.tests.list(
            cursor="cursor",
            page_size=1,
            search="search",
            parent_folder_id="parent_folder_id",
            types=["llm"],
            include_folders=True,
            sort_mode="default",
            sharing_mode="all",
        )
        """
        _response = self._raw_client.list(
            cursor=cursor,
            page_size=page_size,
            search=search,
            parent_folder_id=parent_folder_id,
            types=types,
            include_folders=include_folders,
            sort_mode=sort_mode,
            sharing_mode=sharing_mode,
            request_options=request_options,
        )
        return _response.data

    @property
    def folders(self):
        if self._folders is None:
            from .folders.client import FoldersClient  # noqa: E402

            self._folders = FoldersClient(client_wrapper=self._client_wrapper)
        return self._folders

    @property
    def invocations(self):
        if self._invocations is None:
            from .invocations.client import InvocationsClient  # noqa: E402

            self._invocations = InvocationsClient(client_wrapper=self._client_wrapper)
        return self._invocations


class AsyncTestsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawTestsClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._folders: typing.Optional[AsyncFoldersClient] = None
        self._invocations: typing.Optional[AsyncInvocationsClient] = None

    @property
    def with_raw_response(self) -> AsyncRawTestsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawTestsClient
        """
        return self._raw_client

    async def create(
        self, *, request: TestsCreateRequestBody, request_options: typing.Optional[RequestOptions] = None
    ) -> CreateAgentTestResponseModel:
        """
        Creates a new agent response test.

        Parameters
        ----------
        request : TestsCreateRequestBody

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

        Returns
        -------
        CreateAgentTestResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs
        from elevenlabs.conversational_ai.tests import TestsCreateRequestBody_Llm

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.tests.create(
                request=TestsCreateRequestBody_Llm(
                    name="name",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(request=request, request_options=request_options)
        return _response.data

    async def move(
        self,
        *,
        entity_ids: typing.Sequence[str],
        move_to: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Moves multiple tests or folders from one folder to another.

        Parameters
        ----------
        entity_ids : typing.Sequence[str]
            The IDs of tests or folders to move.

        move_to : typing.Optional[str]
            The folder to move the entities to. If not set, the entities will be moved to the root folder.

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

        Returns
        -------
        typing.Any
            Tests or folders successfully moved to another folder

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.tests.move(
                entity_ids=["entity_ids"],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.move(entity_ids=entity_ids, move_to=move_to, request_options=request_options)
        return _response.data

    async def get(self, test_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> TestsGetResponse:
        """
        Gets an agent response test by ID.

        Parameters
        ----------
        test_id : str
            The id of a chat response test. This is returned on test creation.

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

        Returns
        -------
        TestsGetResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.tests.get(
                test_id="TeaqRRdTcIfIu2i7BYfT",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get(test_id, request_options=request_options)
        return _response.data

    async def update(
        self, test_id: str, *, request: TestsUpdateRequestBody, request_options: typing.Optional[RequestOptions] = None
    ) -> TestsUpdateResponse:
        """
        Updates an agent response test by ID.

        Parameters
        ----------
        test_id : str
            The id of a chat response test. This is returned on test creation.

        request : TestsUpdateRequestBody

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

        Returns
        -------
        TestsUpdateResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs
        from elevenlabs.conversational_ai.tests import TestsUpdateRequestBody_Llm

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.tests.update(
                test_id="TeaqRRdTcIfIu2i7BYfT",
                request=TestsUpdateRequestBody_Llm(
                    name="name",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(test_id, request=request, request_options=request_options)
        return _response.data

    async def delete(self, test_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Any:
        """
        Deletes an agent response test by ID.

        Parameters
        ----------
        test_id : str
            The id of a chat response test. This is returned on test creation.

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

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.tests.delete(
                test_id="TeaqRRdTcIfIu2i7BYfT",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete(test_id, request_options=request_options)
        return _response.data

    async def summaries(
        self, *, test_ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> GetTestsSummariesByIdsResponseModel:
        """
        Gets agent response test summaries for the requested test IDs.

        Parameters
        ----------
        test_ids : typing.Sequence[str]
            List of test IDs to fetch. No duplicates allowed. Prefer at most 1000 IDs per request.

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

        Returns
        -------
        GetTestsSummariesByIdsResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.tests.summaries(
                test_ids=["test_id_1", "test_id_2"],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.summaries(test_ids=test_ids, request_options=request_options)
        return _response.data

    async def list(
        self,
        *,
        cursor: typing.Optional[str] = None,
        page_size: typing.Optional[int] = None,
        search: typing.Optional[str] = None,
        parent_folder_id: typing.Optional[str] = None,
        types: typing.Optional[typing.Union[TestType, typing.Sequence[TestType]]] = None,
        include_folders: typing.Optional[bool] = None,
        sort_mode: typing.Optional[TestsListRequestSortMode] = None,
        sharing_mode: typing.Optional[TestSharingMode] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetTestsPageResponseModel:
        """
        Lists all agent response tests with pagination support and optional search filtering.

        Parameters
        ----------
        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

        page_size : typing.Optional[int]
            How many Tests to return at maximum. Can not exceed 100, defaults to 30.

        search : typing.Optional[str]
            Search query to filter tests by name.

        parent_folder_id : typing.Optional[str]
            Filter by parent folder ID. Use 'root' to get items in the root folder.

        types : typing.Optional[typing.Union[TestType, typing.Sequence[TestType]]]
            If present, the endpoint will return only tests/folders of the given types.

        include_folders : typing.Optional[bool]
            Deprecated. Use the `types` query param and include `folder` instead.

        sort_mode : typing.Optional[TestsListRequestSortMode]
            Sort mode for listing tests. Use 'folders_first' to place folders before tests.

        sharing_mode : typing.Optional[TestSharingMode]
            Filter test visibility. Use `shared_with_me` to return only tests/folders shared with the current user that they did not create.

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

        Returns
        -------
        GetTestsPageResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.tests.list(
                cursor="cursor",
                page_size=1,
                search="search",
                parent_folder_id="parent_folder_id",
                types=["llm"],
                include_folders=True,
                sort_mode="default",
                sharing_mode="all",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            cursor=cursor,
            page_size=page_size,
            search=search,
            parent_folder_id=parent_folder_id,
            types=types,
            include_folders=include_folders,
            sort_mode=sort_mode,
            sharing_mode=sharing_mode,
            request_options=request_options,
        )
        return _response.data

    @property
    def folders(self):
        if self._folders is None:
            from .folders.client import AsyncFoldersClient  # noqa: E402

            self._folders = AsyncFoldersClient(client_wrapper=self._client_wrapper)
        return self._folders

    @property
    def invocations(self):
        if self._invocations is None:
            from .invocations.client import AsyncInvocationsClient  # noqa: E402

            self._invocations = AsyncInvocationsClient(client_wrapper=self._client_wrapper)
        return self._invocations
