# 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.conversation_initiation_client_data_request_input import ConversationInitiationClientDataRequestInput
from ...types.telephony_call_config import TelephonyCallConfig
from ...types.telephony_direction import TelephonyDirection
from ...types.twilio_outbound_call_response import TwilioOutboundCallResponse
from .raw_client import AsyncRawTwilioClient, RawTwilioClient

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


class TwilioClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawTwilioClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawTwilioClient
        """
        return self._raw_client

    def outbound_call(
        self,
        *,
        agent_id: str,
        agent_phone_number_id: str,
        to_number: str,
        conversation_initiation_client_data: typing.Optional[ConversationInitiationClientDataRequestInput] = OMIT,
        call_recording_enabled: typing.Optional[bool] = OMIT,
        telephony_call_config: typing.Optional[TelephonyCallConfig] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TwilioOutboundCallResponse:
        """
        Handle an outbound call via Twilio

        Parameters
        ----------
        agent_id : str

        agent_phone_number_id : str

        to_number : str

        conversation_initiation_client_data : typing.Optional[ConversationInitiationClientDataRequestInput]

        call_recording_enabled : typing.Optional[bool]
            Whether let Twilio record the call.

        telephony_call_config : typing.Optional[TelephonyCallConfig]

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

        Returns
        -------
        TwilioOutboundCallResponse
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.twilio.outbound_call(
            agent_id="agent_id",
            agent_phone_number_id="agent_phone_number_id",
            to_number="to_number",
        )
        """
        _response = self._raw_client.outbound_call(
            agent_id=agent_id,
            agent_phone_number_id=agent_phone_number_id,
            to_number=to_number,
            conversation_initiation_client_data=conversation_initiation_client_data,
            call_recording_enabled=call_recording_enabled,
            telephony_call_config=telephony_call_config,
            request_options=request_options,
        )
        return _response.data

    def register_call(
        self,
        *,
        agent_id: str,
        from_number: str,
        to_number: str,
        direction: typing.Optional[TelephonyDirection] = OMIT,
        conversation_initiation_client_data: typing.Optional[ConversationInitiationClientDataRequestInput] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> str:
        """
        Register a Twilio call and return TwiML to connect the call

        Parameters
        ----------
        agent_id : str

        from_number : str

        to_number : str

        direction : typing.Optional[TelephonyDirection]

        conversation_initiation_client_data : typing.Optional[ConversationInitiationClientDataRequestInput]

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

        Returns
        -------
        str
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.twilio.register_call(
            agent_id="agent_id",
            from_number="from_number",
            to_number="to_number",
        )
        """
        _response = self._raw_client.register_call(
            agent_id=agent_id,
            from_number=from_number,
            to_number=to_number,
            direction=direction,
            conversation_initiation_client_data=conversation_initiation_client_data,
            request_options=request_options,
        )
        return _response.data


class AsyncTwilioClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawTwilioClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawTwilioClient
        """
        return self._raw_client

    async def outbound_call(
        self,
        *,
        agent_id: str,
        agent_phone_number_id: str,
        to_number: str,
        conversation_initiation_client_data: typing.Optional[ConversationInitiationClientDataRequestInput] = OMIT,
        call_recording_enabled: typing.Optional[bool] = OMIT,
        telephony_call_config: typing.Optional[TelephonyCallConfig] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TwilioOutboundCallResponse:
        """
        Handle an outbound call via Twilio

        Parameters
        ----------
        agent_id : str

        agent_phone_number_id : str

        to_number : str

        conversation_initiation_client_data : typing.Optional[ConversationInitiationClientDataRequestInput]

        call_recording_enabled : typing.Optional[bool]
            Whether let Twilio record the call.

        telephony_call_config : typing.Optional[TelephonyCallConfig]

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

        Returns
        -------
        TwilioOutboundCallResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.twilio.outbound_call(
                agent_id="agent_id",
                agent_phone_number_id="agent_phone_number_id",
                to_number="to_number",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.outbound_call(
            agent_id=agent_id,
            agent_phone_number_id=agent_phone_number_id,
            to_number=to_number,
            conversation_initiation_client_data=conversation_initiation_client_data,
            call_recording_enabled=call_recording_enabled,
            telephony_call_config=telephony_call_config,
            request_options=request_options,
        )
        return _response.data

    async def register_call(
        self,
        *,
        agent_id: str,
        from_number: str,
        to_number: str,
        direction: typing.Optional[TelephonyDirection] = OMIT,
        conversation_initiation_client_data: typing.Optional[ConversationInitiationClientDataRequestInput] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> str:
        """
        Register a Twilio call and return TwiML to connect the call

        Parameters
        ----------
        agent_id : str

        from_number : str

        to_number : str

        direction : typing.Optional[TelephonyDirection]

        conversation_initiation_client_data : typing.Optional[ConversationInitiationClientDataRequestInput]

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

        Returns
        -------
        str
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.twilio.register_call(
                agent_id="agent_id",
                from_number="from_number",
                to_number="to_number",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.register_call(
            agent_id=agent_id,
            from_number=from_number,
            to_number=to_number,
            direction=direction,
            conversation_initiation_client_data=conversation_initiation_client_data,
            request_options=request_options,
        )
        return _response.data
