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

import typing

from ....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ....core.request_options import RequestOptions
from ....types.adhoc_agent_config_override_for_test_request_model import AdhocAgentConfigOverrideForTestRequestModel
from ....types.get_test_invocations_page_response_model import GetTestInvocationsPageResponseModel
from ....types.get_test_suite_invocation_response_model import GetTestSuiteInvocationResponseModel
from .raw_client import AsyncRawInvocationsClient, RawInvocationsClient

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


class InvocationsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawInvocationsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawInvocationsClient
        """
        return self._raw_client

    def list(
        self,
        *,
        agent_id: str,
        page_size: typing.Optional[int] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetTestInvocationsPageResponseModel:
        """
        Lists all test invocations with pagination support and optional search filtering.

        Parameters
        ----------
        agent_id : str
            Filter by agent ID

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

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

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

        Returns
        -------
        GetTestInvocationsPageResponseModel
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.tests.invocations.list(
            agent_id="agent_id",
            page_size=1,
            cursor="cursor",
        )
        """
        _response = self._raw_client.list(
            agent_id=agent_id, page_size=page_size, cursor=cursor, request_options=request_options
        )
        return _response.data

    def get(
        self, test_invocation_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetTestSuiteInvocationResponseModel:
        """
        Gets a test invocation by ID.

        Parameters
        ----------
        test_invocation_id : str
            The id of a test invocation. This is returned when tests are run.

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

        Returns
        -------
        GetTestSuiteInvocationResponseModel
            Successful Response

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

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

    def resubmit(
        self,
        test_invocation_id: str,
        *,
        test_run_ids: typing.Sequence[str],
        agent_id: str,
        agent_config_override: typing.Optional[AdhocAgentConfigOverrideForTestRequestModel] = OMIT,
        branch_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Resubmits specific test runs from a test invocation.

        Parameters
        ----------
        test_invocation_id : str
            The id of a test invocation. This is returned when tests are run.

        test_run_ids : typing.Sequence[str]
            List of test run IDs to resubmit

        agent_id : str
            Agent ID to resubmit tests for

        agent_config_override : typing.Optional[AdhocAgentConfigOverrideForTestRequestModel]
            Configuration overrides to use for testing. If not provided, the agent's default configuration will be used.

        branch_id : typing.Optional[str]
            ID of the branch to run the tests on. If not provided, the tests will be run on the agent default configuration.

        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.invocations.resubmit(
            test_invocation_id="test_invocation_id",
            test_run_ids=["test_run_ids"],
            agent_id="agent_id",
        )
        """
        _response = self._raw_client.resubmit(
            test_invocation_id,
            test_run_ids=test_run_ids,
            agent_id=agent_id,
            agent_config_override=agent_config_override,
            branch_id=branch_id,
            request_options=request_options,
        )
        return _response.data


class AsyncInvocationsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawInvocationsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawInvocationsClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        agent_id: str,
        page_size: typing.Optional[int] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetTestInvocationsPageResponseModel:
        """
        Lists all test invocations with pagination support and optional search filtering.

        Parameters
        ----------
        agent_id : str
            Filter by agent ID

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

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

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

        Returns
        -------
        GetTestInvocationsPageResponseModel
            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.invocations.list(
                agent_id="agent_id",
                page_size=1,
                cursor="cursor",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            agent_id=agent_id, page_size=page_size, cursor=cursor, request_options=request_options
        )
        return _response.data

    async def get(
        self, test_invocation_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetTestSuiteInvocationResponseModel:
        """
        Gets a test invocation by ID.

        Parameters
        ----------
        test_invocation_id : str
            The id of a test invocation. This is returned when tests are run.

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

        Returns
        -------
        GetTestSuiteInvocationResponseModel
            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.invocations.get(
                test_invocation_id="test_invocation_id",
            )


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

    async def resubmit(
        self,
        test_invocation_id: str,
        *,
        test_run_ids: typing.Sequence[str],
        agent_id: str,
        agent_config_override: typing.Optional[AdhocAgentConfigOverrideForTestRequestModel] = OMIT,
        branch_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Resubmits specific test runs from a test invocation.

        Parameters
        ----------
        test_invocation_id : str
            The id of a test invocation. This is returned when tests are run.

        test_run_ids : typing.Sequence[str]
            List of test run IDs to resubmit

        agent_id : str
            Agent ID to resubmit tests for

        agent_config_override : typing.Optional[AdhocAgentConfigOverrideForTestRequestModel]
            Configuration overrides to use for testing. If not provided, the agent's default configuration will be used.

        branch_id : typing.Optional[str]
            ID of the branch to run the tests on. If not provided, the tests will be run on the agent default configuration.

        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.invocations.resubmit(
                test_invocation_id="test_invocation_id",
                test_run_ids=["test_run_ids"],
                agent_id="agent_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.resubmit(
            test_invocation_id,
            test_run_ids=test_run_ids,
            agent_id=agent_id,
            agent_config_override=agent_config_override,
            branch_id=branch_id,
            request_options=request_options,
        )
        return _response.data
