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

import typing
import uuid

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..transcribe.types.batch_audio_source import BatchAudioSource
from ..transcribe.types.batch_file_content_type import BatchFileContentType
from ..transcribe.types.batch_file_detail import BatchFileDetail
from ..transcribe.types.batch_file_metadata import BatchFileMetadata
from ..transcribe.types.batch_file_upload_response import BatchFileUploadResponse
from ..transcribe.types.batch_manifest_audio_source import BatchManifestAudioSource
from ..transcribe.types.batch_status_response import BatchStatusResponse
from ..transcribe.types.batch_transcription_response import BatchTranscriptionResponse
from ..transcribe.types.list_batch_files_response import ListBatchFilesResponse
from ..transcribe.types.processing_mode import ProcessingMode
from ..transcribe.types.transcription_request_info import TranscriptionRequestInfo
from .raw_client import AsyncRawBatchTranscribeClient, RawBatchTranscribeClient

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


class BatchTranscribeClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawBatchTranscribeClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawBatchTranscribeClient
        """
        return self._raw_client

    def create_batch_transcription(
        self,
        *,
        info: TranscriptionRequestInfo,
        processing_mode: typing.Optional[ProcessingMode] = OMIT,
        batch_file_id: typing.Optional[uuid.UUID] = OMIT,
        audio_sources: typing.Optional[typing.Sequence[BatchAudioSource]] = OMIT,
        batch_title: typing.Optional[str] = OMIT,
        batch_id: typing.Optional[uuid.UUID] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BatchTranscriptionResponse:
        """
        Create multiple transcriptions in a single batch request.

        **Choose a processing mode:**

        - **Express mode**: Transcriptions start immediately. Max 10 files. Higher cost. Pass `audio_sources` directly in the request. Pricing for v1 is $1.20/hour.
        - **Standard mode**: Transcriptions processed within 24 hours. Max 500 files. Lower cost. First upload a manifest via [Upload Batch Manifest File](/api-reference/batch-transcribe/upload-batch-file), then pass the `batch_file_id` here. Pricing for v1 batch standard is $0.90/hour.

        All files in the batch share the same transcription settings (model, language, etc.) defined in `info`.

        Parameters
        ----------
        info : TranscriptionRequestInfo
            Transcription settings applied to all files in the batch (model, language, etc.)

        processing_mode : typing.Optional[ProcessingMode]
            Choose how the batch is processed:
            - `standard` (default): Lower cost, processed within 24 hours. Max 500 files. Use with `batch_file_id`. Pricing for v1 batch standard is $0.90/hour.
            - `express`: Higher cost, starts immediately. Max 10 files. Use with `audio_sources`. Pricing for v1 is $1.20/hour.

        batch_file_id : typing.Optional[uuid.UUID]
            **For standard mode only.** ID of a previously uploaded batch manifest.

            Get this by calling [Upload Batch Manifest File](/api-reference/batch-transcribe/upload-batch-file) first.

        audio_sources : typing.Optional[typing.Sequence[BatchAudioSource]]
            **For express mode only.** List of audio URLs to transcribe (max 10).

            Each item needs an `audio_url` and can optionally include a `title`.

        batch_title : typing.Optional[str]
            Default title prefix for transcriptions. Individual items can override this. Items without titles become "{batch_title} - Item 1", "{batch_title} - Item 2", etc.

        batch_id : typing.Optional[uuid.UUID]
            Custom UUID for this batch. Auto-generated if not provided.

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

        Returns
        -------
        BatchTranscriptionResponse
            Returns the batch ID and individual transcription IDs. Use [Get Batch Status](/api-reference/batch-transcribe/get-batch-status) to track progress.

        Examples
        --------
        from soferai import SoferAI
        from soferai.transcribe import BatchAudioSource, TranscriptionRequestInfo

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.batch_transcribe.create_batch_transcription(
            audio_sources=[
                BatchAudioSource(
                    audio_url="https://example.com/audio1.mp3",
                    title="Rabbi Cohen's Shiur on Shabbos",
                ),
                BatchAudioSource(
                    audio_url="https://example.com/audio2.mp3",
                    title="Rabbi Cohen's Shiur on Kashrus",
                ),
            ],
            info=TranscriptionRequestInfo(
                model="v1",
                primary_language="en",
                hebrew_word_format=["en", "he"],
                num_speakers=1,
            ),
            batch_title="Rabbi Cohen Shiurim",
            processing_mode="express",
        )
        """
        _response = self._raw_client.create_batch_transcription(
            info=info,
            processing_mode=processing_mode,
            batch_file_id=batch_file_id,
            audio_sources=audio_sources,
            batch_title=batch_title,
            batch_id=batch_id,
            request_options=request_options,
        )
        return _response.data

    def upload_batch_file(
        self,
        *,
        content_type: BatchFileContentType,
        json_items: typing.Optional[typing.Sequence[BatchManifestAudioSource]] = OMIT,
        jsonl: typing.Optional[str] = OMIT,
        metadata: typing.Optional[BatchFileMetadata] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BatchFileUploadResponse:
        """
        Upload a batch manifest containing audio URLs for standard mode batch processing.

        **Workflow:**
        1. Upload your manifest here to get a `batch_file_id`
        2. Use that ID in [Create Batch Transcription](/api-reference/batch-transcribe/create-batch-transcription) with `processing_mode: "standard"`

        The manifest is a list of audio sources (max 500), each with a URL and optional title. You can provide it as a JSON array or JSONL format.

        Parameters
        ----------
        content_type : BatchFileContentType
            Format of your manifest data

        json_items : typing.Optional[typing.Sequence[BatchManifestAudioSource]]
            **For JSON format.** Array of audio sources to transcribe (max 500).

        jsonl : typing.Optional[str]
            **For JSONL format.** One audio source per line as JSON, separated by newlines (max 500 lines).

            Example: `{"audio_url": "https://..."}\n{"audio_url": "https://..."}`

        metadata : typing.Optional[BatchFileMetadata]
            Optional title and description for this manifest

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

        Returns
        -------
        BatchFileUploadResponse

        Examples
        --------
        from soferai import SoferAI
        from soferai.transcribe import BatchFileMetadata, BatchManifestAudioSource

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.batch_transcribe.upload_batch_file(
            content_type="json",
            json_items=[
                BatchManifestAudioSource(
                    audio_url="https://example.com/shiur1.mp3",
                    title="Parshas Bereishis - Rabbi Cohen",
                ),
                BatchManifestAudioSource(
                    audio_url="https://example.com/shiur2.mp3",
                    title="Parshas Noach - Rabbi Cohen",
                ),
                BatchManifestAudioSource(
                    audio_url="https://example.com/shiur3.mp3",
                    title="Parshas Lech Lecha - Rabbi Cohen",
                ),
            ],
            metadata=BatchFileMetadata(
                title="Rabbi Cohen Weekly Parsha Series",
                description="Shiurim from Fall 2024",
            ),
        )
        """
        _response = self._raw_client.upload_batch_file(
            content_type=content_type,
            json_items=json_items,
            jsonl=jsonl,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    def list_batch_files(self, *, request_options: typing.Optional[RequestOptions] = None) -> ListBatchFilesResponse:
        """
        List all batch file manifests you've uploaded. Use this to find a `batch_file_id` for starting a standard mode batch.

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

        Returns
        -------
        ListBatchFilesResponse

        Examples
        --------
        from soferai import SoferAI

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.batch_transcribe.list_batch_files()
        """
        _response = self._raw_client.list_batch_files(request_options=request_options)
        return _response.data

    def get_batch_file(
        self, batch_file_id: uuid.UUID, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BatchFileDetail:
        """
        Get details about a specific batch file manifest, including its validation status. Check this after uploading to ensure your manifest is valid before starting a batch.

        Parameters
        ----------
        batch_file_id : uuid.UUID
            The batch file ID returned from [Upload Batch File](/api-reference/batch-transcribe/upload-batch-file)

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

        Returns
        -------
        BatchFileDetail

        Examples
        --------
        import uuid

        from soferai import SoferAI

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.batch_transcribe.get_batch_file(
            batch_file_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
        )
        """
        _response = self._raw_client.get_batch_file(batch_file_id, request_options=request_options)
        return _response.data

    def get_batch_status(
        self, batch_id: uuid.UUID, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BatchStatusResponse:
        """
        Check the progress of a batch transcription. Returns counts of completed, failed, and pending transcriptions, plus details for each individual transcription.

        Parameters
        ----------
        batch_id : uuid.UUID
            The batch ID returned from [Create Batch Transcription](/api-reference/batch-transcribe/create-batch-transcription)

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

        Returns
        -------
        BatchStatusResponse

        Examples
        --------
        import uuid

        from soferai import SoferAI

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.batch_transcribe.get_batch_status(
            batch_id=uuid.UUID(
                "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
            ),
        )
        """
        _response = self._raw_client.get_batch_status(batch_id, request_options=request_options)
        return _response.data


class AsyncBatchTranscribeClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawBatchTranscribeClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawBatchTranscribeClient
        """
        return self._raw_client

    async def create_batch_transcription(
        self,
        *,
        info: TranscriptionRequestInfo,
        processing_mode: typing.Optional[ProcessingMode] = OMIT,
        batch_file_id: typing.Optional[uuid.UUID] = OMIT,
        audio_sources: typing.Optional[typing.Sequence[BatchAudioSource]] = OMIT,
        batch_title: typing.Optional[str] = OMIT,
        batch_id: typing.Optional[uuid.UUID] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BatchTranscriptionResponse:
        """
        Create multiple transcriptions in a single batch request.

        **Choose a processing mode:**

        - **Express mode**: Transcriptions start immediately. Max 10 files. Higher cost. Pass `audio_sources` directly in the request. Pricing for v1 is $1.20/hour.
        - **Standard mode**: Transcriptions processed within 24 hours. Max 500 files. Lower cost. First upload a manifest via [Upload Batch Manifest File](/api-reference/batch-transcribe/upload-batch-file), then pass the `batch_file_id` here. Pricing for v1 batch standard is $0.90/hour.

        All files in the batch share the same transcription settings (model, language, etc.) defined in `info`.

        Parameters
        ----------
        info : TranscriptionRequestInfo
            Transcription settings applied to all files in the batch (model, language, etc.)

        processing_mode : typing.Optional[ProcessingMode]
            Choose how the batch is processed:
            - `standard` (default): Lower cost, processed within 24 hours. Max 500 files. Use with `batch_file_id`. Pricing for v1 batch standard is $0.90/hour.
            - `express`: Higher cost, starts immediately. Max 10 files. Use with `audio_sources`. Pricing for v1 is $1.20/hour.

        batch_file_id : typing.Optional[uuid.UUID]
            **For standard mode only.** ID of a previously uploaded batch manifest.

            Get this by calling [Upload Batch Manifest File](/api-reference/batch-transcribe/upload-batch-file) first.

        audio_sources : typing.Optional[typing.Sequence[BatchAudioSource]]
            **For express mode only.** List of audio URLs to transcribe (max 10).

            Each item needs an `audio_url` and can optionally include a `title`.

        batch_title : typing.Optional[str]
            Default title prefix for transcriptions. Individual items can override this. Items without titles become "{batch_title} - Item 1", "{batch_title} - Item 2", etc.

        batch_id : typing.Optional[uuid.UUID]
            Custom UUID for this batch. Auto-generated if not provided.

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

        Returns
        -------
        BatchTranscriptionResponse
            Returns the batch ID and individual transcription IDs. Use [Get Batch Status](/api-reference/batch-transcribe/get-batch-status) to track progress.

        Examples
        --------
        import asyncio

        from soferai import AsyncSoferAI
        from soferai.transcribe import BatchAudioSource, TranscriptionRequestInfo

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.batch_transcribe.create_batch_transcription(
                audio_sources=[
                    BatchAudioSource(
                        audio_url="https://example.com/audio1.mp3",
                        title="Rabbi Cohen's Shiur on Shabbos",
                    ),
                    BatchAudioSource(
                        audio_url="https://example.com/audio2.mp3",
                        title="Rabbi Cohen's Shiur on Kashrus",
                    ),
                ],
                info=TranscriptionRequestInfo(
                    model="v1",
                    primary_language="en",
                    hebrew_word_format=["en", "he"],
                    num_speakers=1,
                ),
                batch_title="Rabbi Cohen Shiurim",
                processing_mode="express",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_batch_transcription(
            info=info,
            processing_mode=processing_mode,
            batch_file_id=batch_file_id,
            audio_sources=audio_sources,
            batch_title=batch_title,
            batch_id=batch_id,
            request_options=request_options,
        )
        return _response.data

    async def upload_batch_file(
        self,
        *,
        content_type: BatchFileContentType,
        json_items: typing.Optional[typing.Sequence[BatchManifestAudioSource]] = OMIT,
        jsonl: typing.Optional[str] = OMIT,
        metadata: typing.Optional[BatchFileMetadata] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BatchFileUploadResponse:
        """
        Upload a batch manifest containing audio URLs for standard mode batch processing.

        **Workflow:**
        1. Upload your manifest here to get a `batch_file_id`
        2. Use that ID in [Create Batch Transcription](/api-reference/batch-transcribe/create-batch-transcription) with `processing_mode: "standard"`

        The manifest is a list of audio sources (max 500), each with a URL and optional title. You can provide it as a JSON array or JSONL format.

        Parameters
        ----------
        content_type : BatchFileContentType
            Format of your manifest data

        json_items : typing.Optional[typing.Sequence[BatchManifestAudioSource]]
            **For JSON format.** Array of audio sources to transcribe (max 500).

        jsonl : typing.Optional[str]
            **For JSONL format.** One audio source per line as JSON, separated by newlines (max 500 lines).

            Example: `{"audio_url": "https://..."}\n{"audio_url": "https://..."}`

        metadata : typing.Optional[BatchFileMetadata]
            Optional title and description for this manifest

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

        Returns
        -------
        BatchFileUploadResponse

        Examples
        --------
        import asyncio

        from soferai import AsyncSoferAI
        from soferai.transcribe import BatchFileMetadata, BatchManifestAudioSource

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.batch_transcribe.upload_batch_file(
                content_type="json",
                json_items=[
                    BatchManifestAudioSource(
                        audio_url="https://example.com/shiur1.mp3",
                        title="Parshas Bereishis - Rabbi Cohen",
                    ),
                    BatchManifestAudioSource(
                        audio_url="https://example.com/shiur2.mp3",
                        title="Parshas Noach - Rabbi Cohen",
                    ),
                    BatchManifestAudioSource(
                        audio_url="https://example.com/shiur3.mp3",
                        title="Parshas Lech Lecha - Rabbi Cohen",
                    ),
                ],
                metadata=BatchFileMetadata(
                    title="Rabbi Cohen Weekly Parsha Series",
                    description="Shiurim from Fall 2024",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.upload_batch_file(
            content_type=content_type,
            json_items=json_items,
            jsonl=jsonl,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    async def list_batch_files(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ListBatchFilesResponse:
        """
        List all batch file manifests you've uploaded. Use this to find a `batch_file_id` for starting a standard mode batch.

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

        Returns
        -------
        ListBatchFilesResponse

        Examples
        --------
        import asyncio

        from soferai import AsyncSoferAI

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.batch_transcribe.list_batch_files()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_batch_files(request_options=request_options)
        return _response.data

    async def get_batch_file(
        self, batch_file_id: uuid.UUID, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BatchFileDetail:
        """
        Get details about a specific batch file manifest, including its validation status. Check this after uploading to ensure your manifest is valid before starting a batch.

        Parameters
        ----------
        batch_file_id : uuid.UUID
            The batch file ID returned from [Upload Batch File](/api-reference/batch-transcribe/upload-batch-file)

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

        Returns
        -------
        BatchFileDetail

        Examples
        --------
        import asyncio
        import uuid

        from soferai import AsyncSoferAI

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.batch_transcribe.get_batch_file(
                batch_file_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
            )


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

    async def get_batch_status(
        self, batch_id: uuid.UUID, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BatchStatusResponse:
        """
        Check the progress of a batch transcription. Returns counts of completed, failed, and pending transcriptions, plus details for each individual transcription.

        Parameters
        ----------
        batch_id : uuid.UUID
            The batch ID returned from [Create Batch Transcription](/api-reference/batch-transcribe/create-batch-transcription)

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

        Returns
        -------
        BatchStatusResponse

        Examples
        --------
        import asyncio
        import uuid

        from soferai import AsyncSoferAI

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.batch_transcribe.get_batch_status(
                batch_id=uuid.UUID(
                    "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
                ),
            )


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