# 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 ..requests.bulk_job_callback import BulkJobCallbackParams
from ..requests.speech_to_text_job_parameters import SpeechToTextJobParametersParams
from ..types.bulk_job_init_response_v_1 import BulkJobInitResponseV1
from ..types.files_download_response import FilesDownloadResponse
from ..types.files_upload_response import FilesUploadResponse
from ..types.job_status_v_1_response import JobStatusV1Response
from ..types.speech_to_text_model import SpeechToTextModel
from ..types.speech_to_text_language import SpeechToTextLanguage
from ..types.mode import Mode
from .raw_client import AsyncRawSpeechToTextJobClient, RawSpeechToTextJobClient
from .job import AsyncSpeechToTextJob, SpeechToTextJob

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


class SpeechToTextJobClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawSpeechToTextJobClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawSpeechToTextJobClient
        """
        return self._raw_client

    def initialise(
        self,
        *,
        job_parameters: SpeechToTextJobParametersParams,
        callback: typing.Optional[BulkJobCallbackParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BulkJobInitResponseV1:
        """
        Get a job uuid, and storage folder details for speech to text bulk job v1

        Parameters
        ----------
        job_parameters : SpeechToTextJobParametersParams
            Job Parameters for the bulk job

        callback : typing.Optional[BulkJobCallbackParams]
            Parameters for callback URL

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

        Returns
        -------
        BulkJobInitResponseV1
            Successful Response

        Examples
        --------
        from sarvamai import SarvamAI

        client = SarvamAI(
            api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
        )
        client.speech_to_text_job.initialise(
            job_parameters={},
        )
        """
        _response = self._raw_client.initialise(
            job_parameters=job_parameters,
            callback=callback,
            request_options=request_options,
        )
        return _response.data

    def get_status(
        self, job_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> JobStatusV1Response:
        """
        Get the status of a speech to text bulk job V1

        Parameters
        ----------
        job_id : str
            The unique identifier of the job

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

        Returns
        -------
        JobStatusV1Response
            Successful Response

        Examples
        --------
        from sarvamai import SarvamAI

        client = SarvamAI(
            api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
        )
        client.speech_to_text_job.get_status(
            job_id="job_id",
        )
        """
        _response = self._raw_client.get_status(job_id, request_options=request_options)
        return _response.data

    def start(
        self,
        job_id: str,
        *,
        ptu_id: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> JobStatusV1Response:
        """
        Start a speech to text bulk job V1

        Parameters
        ----------
        job_id : str
            The unique identifier of the job

        ptu_id : typing.Optional[int]

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

        Returns
        -------
        JobStatusV1Response
            Successful Response

        Examples
        --------
        from sarvamai import SarvamAI

        client = SarvamAI(
            api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
        )
        client.speech_to_text_job.start(
            job_id="job_id",
        )
        """
        _response = self._raw_client.start(
            job_id, ptu_id=ptu_id, request_options=request_options
        )
        return _response.data

    def get_upload_links(
        self,
        *,
        job_id: str,
        files: typing.Sequence[str],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FilesUploadResponse:
        """
        Start a speech to text bulk job V1

        Parameters
        ----------
        job_id : str

        files : typing.Sequence[str]

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

        Returns
        -------
        FilesUploadResponse
            Successful Response

        Examples
        --------
        from sarvamai import SarvamAI

        client = SarvamAI(
            api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
        )
        client.speech_to_text_job.get_upload_links(
            job_id="job_id",
            files=["files"],
        )
        """
        _response = self._raw_client.get_upload_links(
            job_id=job_id, files=files, request_options=request_options
        )
        return _response.data

    def get_download_links(
        self,
        *,
        job_id: str,
        files: typing.Sequence[str],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FilesDownloadResponse:
        """
        Start a speech to text bulk job V1

        Parameters
        ----------
        job_id : str

        files : typing.Sequence[str]

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

        Returns
        -------
        FilesDownloadResponse
            Successful Response

        Examples
        --------
        from sarvamai import SarvamAI

        client = SarvamAI(
            api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
        )
        client.speech_to_text_job.get_download_links(
            job_id="job_id",
            files=["files"],
        )
        """
        _response = self._raw_client.get_download_links(
            job_id=job_id, files=files, request_options=request_options
        )
        return _response.data

    def create_job(
        self,
        model: SpeechToTextModel = "saarika:v2.5",
        mode: typing.Optional[Mode] = None,
        with_diarization: bool = False,
        with_timestamps: bool = False,
        language_code: typing.Optional[SpeechToTextLanguage] = None,
        num_speakers: typing.Optional[int] = None,
        callback: typing.Optional[BulkJobCallbackParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SpeechToTextJob:
        """
        Create a new Speech-to-Text bulk job.

        Parameters
        ----------
        model : SpeechToTextModel, default="saarika:v2.5"
            The model to use for transcription.

        mode : typing.Optional[Mode], default=None
            Mode of operation. Only applicable for saaras:v3 model.
            Options: transcribe, translate, indic-en, verbatim, translit, codemix

        with_diarization : typing.Optional[bool], default=False
            Whether to enable speaker diarization (distinguishing who said what).

        with_timestamps : typing.Optional[bool], default=False
            Whether to include word-level timestamps in the transcription output.

        language_code : typing.Optional[SpeechToTextLanguage], default=None
            The language code of the input audio (e.g., "hi-IN", "bn-IN").

        num_speakers : typing.Optional[int], default=None
            The number of distinct speakers in the audio, if known.

        callback : typing.Optional[BulkJobCallbackParams], default=OMIT
            Optional callback configuration to receive job completion events.

        request_options : typing.Optional[RequestOptions], default=None
            Request-specific configuration.

        Returns
        -------
        SpeechToTextJob
            A handle to the newly created Speech-to-Text job.
        """
        response = self.initialise(
            job_parameters=SpeechToTextJobParametersParams(
                language_code=language_code,
                model=model,
                mode=mode,  # type: ignore[typeddict-item]
                num_speakers=num_speakers,  # type: ignore[typeddict-item]
                with_diarization=with_diarization,
                with_timestamps=with_timestamps,
            ),
            callback=callback,
            request_options=request_options,
        )
        return SpeechToTextJob(job_id=response.job_id, client=self)

    def get_job(self, job_id: str) -> SpeechToTextJob:
        """
        Get an existing Speech-to-Text job handle by job ID.

        Parameters
        ----------
        job_id : str
            The job ID of the previously created Speech-to-Text job.

        Returns
        -------
        SpeechToTextJob
            A job handle which can be used to check status or retrieve results.
        """
        return SpeechToTextJob(job_id=job_id, client=self)


class AsyncSpeechToTextJobClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawSpeechToTextJobClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawSpeechToTextJobClient
        """
        return self._raw_client

    async def initialise(
        self,
        *,
        job_parameters: SpeechToTextJobParametersParams,
        callback: typing.Optional[BulkJobCallbackParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BulkJobInitResponseV1:
        """
        Get a job uuid, and storage folder details for speech to text bulk job v1

        Parameters
        ----------
        job_parameters : SpeechToTextJobParametersParams
            Job Parameters for the bulk job

        callback : typing.Optional[BulkJobCallbackParams]
            Parameters for callback URL

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

        Returns
        -------
        BulkJobInitResponseV1
            Successful Response

        Examples
        --------
        import asyncio

        from sarvamai import AsyncSarvamAI

        client = AsyncSarvamAI(
            api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
        )


        async def main() -> None:
            await client.speech_to_text_job.initialise(
                job_parameters={},
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.initialise(
            job_parameters=job_parameters,
            callback=callback,
            request_options=request_options,
        )
        return _response.data

    async def get_status(
        self, job_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> JobStatusV1Response:
        """
        Get the status of a speech to text bulk job V1

        Parameters
        ----------
        job_id : str
            The unique identifier of the job

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

        Returns
        -------
        JobStatusV1Response
            Successful Response

        Examples
        --------
        import asyncio

        from sarvamai import AsyncSarvamAI

        client = AsyncSarvamAI(
            api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
        )


        async def main() -> None:
            await client.speech_to_text_job.get_status(
                job_id="job_id",
            )


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

    async def start(
        self,
        job_id: str,
        *,
        ptu_id: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> JobStatusV1Response:
        """
        Start a speech to text bulk job V1

        Parameters
        ----------
        job_id : str
            The unique identifier of the job

        ptu_id : typing.Optional[int]

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

        Returns
        -------
        JobStatusV1Response
            Successful Response

        Examples
        --------
        import asyncio

        from sarvamai import AsyncSarvamAI

        client = AsyncSarvamAI(
            api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
        )


        async def main() -> None:
            await client.speech_to_text_job.start(
                job_id="job_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.start(
            job_id, ptu_id=ptu_id, request_options=request_options
        )
        return _response.data

    async def get_upload_links(
        self,
        *,
        job_id: str,
        files: typing.Sequence[str],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FilesUploadResponse:
        """
        Start a speech to text bulk job V1

        Parameters
        ----------
        job_id : str

        files : typing.Sequence[str]

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

        Returns
        -------
        FilesUploadResponse
            Successful Response

        Examples
        --------
        import asyncio

        from sarvamai import AsyncSarvamAI

        client = AsyncSarvamAI(
            api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
        )


        async def main() -> None:
            await client.speech_to_text_job.get_upload_links(
                job_id="job_id",
                files=["files"],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_upload_links(
            job_id=job_id, files=files, request_options=request_options
        )
        return _response.data

    async def get_download_links(
        self,
        *,
        job_id: str,
        files: typing.Sequence[str],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FilesDownloadResponse:
        """
        Start a speech to text bulk job V1

        Parameters
        ----------
        job_id : str

        files : typing.Sequence[str]

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

        Returns
        -------
        FilesDownloadResponse
            Successful Response

        Examples
        --------
        import asyncio

        from sarvamai import AsyncSarvamAI

        client = AsyncSarvamAI(
            api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
        )


        async def main() -> None:
            await client.speech_to_text_job.get_download_links(
                job_id="job_id",
                files=["files"],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_download_links(
            job_id=job_id, files=files, request_options=request_options
        )
        return _response.data

    async def create_job(
        self,
        model: SpeechToTextModel = "saarika:v2.5",
        mode: typing.Optional[Mode] = None,
        with_diarization: bool = False,
        with_timestamps: bool = False,
        language_code: typing.Optional[SpeechToTextLanguage] = None,
        num_speakers: typing.Optional[int] = None,
        callback: typing.Optional[BulkJobCallbackParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> "AsyncSpeechToTextJob":
        """
        Create a new Speech-to-Text bulk job.

        Parameters
        ----------
        model : SpeechToTextModel, default="saarika:v2.5"
            The model to use for transcription.

        mode : typing.Optional[Mode], default=None
            Mode of operation. Only applicable for saaras:v3 model.
            Options: transcribe, translate, indic-en, verbatim, translit, codemix

        with_diarization : typing.Optional[bool], default=False
            Whether to enable speaker diarization (distinguishing who said what).

        with_timestamps : typing.Optional[bool], default=False
            Whether to include word-level timestamps in the transcription output.

        language_code : typing.Optional[SpeechToTextLanguage], default=None
            The language code of the input audio (e.g., "hi-IN", "bn-IN").

        num_speakers : typing.Optional[int] = None
            The number of distinct speakers in the audio, if known.

        callback : typing.Optional[BulkJobCallbackParams], default=OMIT
            Optional callback configuration to receive job completion events.

        request_options : typing.Optional[RequestOptions], default=None
            Request-specific configuration.

        Returns
        -------
        AsyncSpeechToTextJob
            A handle to the newly created job.
        """
        response = await self.initialise(
            job_parameters=SpeechToTextJobParametersParams(
                language_code=language_code,
                model=model,
                mode=mode,  # type: ignore[typeddict-item]
                with_diarization=with_diarization,
                with_timestamps=with_timestamps,
                num_speakers=num_speakers,  # type: ignore[typeddict-item]
            ),
            callback=callback,
            request_options=request_options,
        )
        return AsyncSpeechToTextJob(job_id=response.job_id, client=self)

    async def get_job(self, job_id: str) -> "AsyncSpeechToTextJob":
        """
        Get an existing Speech-to-Text job handle by job ID.

        Parameters
        ----------
        job_id : str
            The job ID of the previously created speech-to-text job.

        Returns
        -------
        AsyncSpeechToTextJob
            A job handle which can be used to check status or retrieve results.
        """
        return AsyncSpeechToTextJob(job_id=job_id, client=self)
