# 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.orchestrator_pipeline_call_result import OrchestratorPipelineCallResult
from ..types.orchestrator_pipeline_result import OrchestratorPipelineResult
from ..types.text_to_audio_result import TextToAudioResult
from ..types.text_to_audio_type import TextToAudioType
from .raw_client import AsyncRawTextToAudioClient, RawTextToAudioClient

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


class TextToAudioClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawTextToAudioClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawTextToAudioClient
        """
        return self._raw_client

    def create_text_to_audio(
        self,
        *,
        prompt: str,
        run_id: typing.Optional[int] = None,
        traceparent: typing.Optional[str] = None,
        project_name: typing.Optional[str] = OMIT,
        project_description: typing.Optional[str] = OMIT,
        folder_id: typing.Optional[int] = OMIT,
        duration: typing.Optional[float] = OMIT,
        audio_type: typing.Optional[TextToAudioType] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> OrchestratorPipelineCallResult:
        """
        Parameters
        ----------
        prompt : str
            The text to be converted to audio.

        run_id : typing.Optional[int]

        traceparent : typing.Optional[str]

        project_name : typing.Optional[str]

        project_description : typing.Optional[str]

        folder_id : typing.Optional[int]

        duration : typing.Optional[float]
            The desired duration of the audio.

        audio_type : typing.Optional[TextToAudioType]
            The audio type preference.

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

        Returns
        -------
        OrchestratorPipelineCallResult
            Successful Response

        Examples
        --------
        from camb import CambApi

        client = CambApi(
            api_key="YOUR_API_KEY",
        )
        client.text_to_audio.create_text_to_audio(
            prompt="prompt",
        )
        """
        _response = self._raw_client.create_text_to_audio(
            prompt=prompt,
            run_id=run_id,
            traceparent=traceparent,
            project_name=project_name,
            project_description=project_description,
            folder_id=folder_id,
            duration=duration,
            audio_type=audio_type,
            request_options=request_options,
        )
        return _response.data

    def get_text_to_audio_status(
        self,
        task_id: str,
        *,
        run_id: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> OrchestratorPipelineResult:
        """
        Parameters
        ----------
        task_id : str

        run_id : typing.Optional[int]

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

        Returns
        -------
        OrchestratorPipelineResult
            Successful Response

        Examples
        --------
        from camb import CambApi

        client = CambApi(
            api_key="YOUR_API_KEY",
        )
        client.text_to_audio.get_text_to_audio_status(
            task_id="task_id",
        )
        """
        _response = self._raw_client.get_text_to_audio_status(task_id, run_id=run_id, request_options=request_options)
        return _response.data

    def get_text_to_audio_result(
        self,
        run_id: typing.Optional[int],
        *,
        output_type: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[bytes]:
        """
        Retrieve the Text-to-Audio (TTA) result for a given run.

        This endpoint validates the provided run ID and retrieves the associated
        Text-to-Audio output. It supports two output formats:
        - RAW_BYTES: Streams the audio file in WAV format.
        - FILE_URL: Returns a pre-signed URL for downloading the audio file.

        The endpoint ensures that the run type is valid for Text-to-Audio processing
        and that the storage preferences are applied accordingly.

        Args:
            run_id (int): Unique identifier for the TTA run.
            traceparent (Optional[str]): Trace header for distributed tracing.
            api_key_obj (dict): API key object containing authentication and storage preferences.
            output_type (OutputType): Desired output format. Defaults to RAW_BYTES.

        Returns:
            StreamingResponse | GetTTAOut:
                - StreamingResponse: If output_type is RAW_BYTES, a streaming response with the audio in WAV format.
                - GetTTAOut: If output_type is FILE_URL, a pre-signed URL to access the audio file.

        Raises:
            HTTPException:
                - 400 BAD REQUEST: If the run type is invalid for a TTA run.
                - 500 INTERNAL SERVER ERROR: If the audio file cannot be fetched or streamed.

        Parameters
        ----------
        run_id : typing.Optional[int]

        output_type : typing.Optional[str]
            Output format for the Text To Speech result

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.Iterator[bytes]
            Successful Response
        """
        with self._raw_client.get_text_to_audio_result(
            run_id, output_type=output_type, request_options=request_options
        ) as r:
            yield from r.data

    def get_text_to_sound_results(
        self,
        *,
        run_ids: typing.Sequence[int],
        run_id: typing.Optional[int] = None,
        traceparent: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, TextToAudioResult]:
        """
        Parameters
        ----------
        run_ids : typing.Sequence[int]

        run_id : typing.Optional[int]

        traceparent : typing.Optional[str]

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

        Returns
        -------
        typing.Dict[str, TextToAudioResult]
            Successful Response

        Examples
        --------
        from camb import CambApi

        client = CambApi(
            api_key="YOUR_API_KEY",
        )
        client.text_to_audio.get_text_to_sound_results(
            run_ids=[1],
        )
        """
        _response = self._raw_client.get_text_to_sound_results(
            run_ids=run_ids, run_id=run_id, traceparent=traceparent, request_options=request_options
        )
        return _response.data


class AsyncTextToAudioClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawTextToAudioClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawTextToAudioClient
        """
        return self._raw_client

    async def create_text_to_audio(
        self,
        *,
        prompt: str,
        run_id: typing.Optional[int] = None,
        traceparent: typing.Optional[str] = None,
        project_name: typing.Optional[str] = OMIT,
        project_description: typing.Optional[str] = OMIT,
        folder_id: typing.Optional[int] = OMIT,
        duration: typing.Optional[float] = OMIT,
        audio_type: typing.Optional[TextToAudioType] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> OrchestratorPipelineCallResult:
        """
        Parameters
        ----------
        prompt : str
            The text to be converted to audio.

        run_id : typing.Optional[int]

        traceparent : typing.Optional[str]

        project_name : typing.Optional[str]

        project_description : typing.Optional[str]

        folder_id : typing.Optional[int]

        duration : typing.Optional[float]
            The desired duration of the audio.

        audio_type : typing.Optional[TextToAudioType]
            The audio type preference.

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

        Returns
        -------
        OrchestratorPipelineCallResult
            Successful Response

        Examples
        --------
        import asyncio

        from camb import AsyncCambApi

        client = AsyncCambApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.text_to_audio.create_text_to_audio(
                prompt="prompt",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_text_to_audio(
            prompt=prompt,
            run_id=run_id,
            traceparent=traceparent,
            project_name=project_name,
            project_description=project_description,
            folder_id=folder_id,
            duration=duration,
            audio_type=audio_type,
            request_options=request_options,
        )
        return _response.data

    async def get_text_to_audio_status(
        self,
        task_id: str,
        *,
        run_id: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> OrchestratorPipelineResult:
        """
        Parameters
        ----------
        task_id : str

        run_id : typing.Optional[int]

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

        Returns
        -------
        OrchestratorPipelineResult
            Successful Response

        Examples
        --------
        import asyncio

        from camb import AsyncCambApi

        client = AsyncCambApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.text_to_audio.get_text_to_audio_status(
                task_id="task_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_text_to_audio_status(
            task_id, run_id=run_id, request_options=request_options
        )
        return _response.data

    async def get_text_to_audio_result(
        self,
        run_id: typing.Optional[int],
        *,
        output_type: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[bytes]:
        """
        Retrieve the Text-to-Audio (TTA) result for a given run.

        This endpoint validates the provided run ID and retrieves the associated
        Text-to-Audio output. It supports two output formats:
        - RAW_BYTES: Streams the audio file in WAV format.
        - FILE_URL: Returns a pre-signed URL for downloading the audio file.

        The endpoint ensures that the run type is valid for Text-to-Audio processing
        and that the storage preferences are applied accordingly.

        Args:
            run_id (int): Unique identifier for the TTA run.
            traceparent (Optional[str]): Trace header for distributed tracing.
            api_key_obj (dict): API key object containing authentication and storage preferences.
            output_type (OutputType): Desired output format. Defaults to RAW_BYTES.

        Returns:
            StreamingResponse | GetTTAOut:
                - StreamingResponse: If output_type is RAW_BYTES, a streaming response with the audio in WAV format.
                - GetTTAOut: If output_type is FILE_URL, a pre-signed URL to access the audio file.

        Raises:
            HTTPException:
                - 400 BAD REQUEST: If the run type is invalid for a TTA run.
                - 500 INTERNAL SERVER ERROR: If the audio file cannot be fetched or streamed.

        Parameters
        ----------
        run_id : typing.Optional[int]

        output_type : typing.Optional[str]
            Output format for the Text To Speech result

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.AsyncIterator[bytes]
            Successful Response
        """
        async with self._raw_client.get_text_to_audio_result(
            run_id, output_type=output_type, request_options=request_options
        ) as r:
            async for _chunk in r.data:
                yield _chunk

    async def get_text_to_sound_results(
        self,
        *,
        run_ids: typing.Sequence[int],
        run_id: typing.Optional[int] = None,
        traceparent: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, TextToAudioResult]:
        """
        Parameters
        ----------
        run_ids : typing.Sequence[int]

        run_id : typing.Optional[int]

        traceparent : typing.Optional[str]

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

        Returns
        -------
        typing.Dict[str, TextToAudioResult]
            Successful Response

        Examples
        --------
        import asyncio

        from camb import AsyncCambApi

        client = AsyncCambApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.text_to_audio.get_text_to_sound_results(
                run_ids=[1],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_text_to_sound_results(
            run_ids=run_ids, run_id=run_id, traceparent=traceparent, request_options=request_options
        )
        return _response.data
