# 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 ..transcribe.types.language import Language
from ..transcribe.types.timestamp import Timestamp
from ..transcribe.types.transcription_id import TranscriptionId
from .raw_client import AsyncRawTimestampsClient, RawTimestampsClient
from .types.outline_topic import OutlineTopic

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


class TimestampsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawTimestampsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawTimestampsClient
        """
        return self._raw_client

    def outline(
        self,
        *,
        transcription_id: TranscriptionId,
        monotone: typing.Optional[bool] = OMIT,
        conclusion_bias: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[OutlineTopic]:
        """
        Outline of topics discussed by timestamp, generated end-to-end from a transcription ID.

        This endpoint will:
        1) Fetch the transcript and word-level timestamps for the given transcription
        2) Generate chapter topics (title + starting_phrase) using an LLM from the transcript text
        3) Align each topic's starting phrase to timestamps

        Parameters
        ----------
        transcription_id : TranscriptionId
            ID of the transcription to process end-to-end

        monotone : typing.Optional[bool]
            If true, each topic is searched after the previous topic's start (with a small backoff)

        conclusion_bias : typing.Optional[bool]
            If true and a title includes the word "conclusion", search in the last third of the audio

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

        Returns
        -------
        typing.List[OutlineTopic]

        Examples
        --------
        import uuid

        from soferai import SoferAI

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.timestamps.outline(
            transcription_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
        )
        """
        _response = self._raw_client.outline(
            transcription_id=transcription_id,
            monotone=monotone,
            conclusion_bias=conclusion_bias,
            request_options=request_options,
        )
        return _response.data

    def update_timestamps(
        self,
        *,
        old_timestamps: typing.Sequence[Timestamp],
        edited_text: str,
        language_to_update: typing.Optional[Language] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[Timestamp]:
        """
        Update the timestamps based on edited text.

        Parameters
        ----------
        old_timestamps : typing.Sequence[Timestamp]
            The original timestamps associated with the text before editing. These will be used as reference points to align the new timestamps.

        edited_text : str
            The modified version of the transcription text that needs updated timestamp alignments. This should be the complete text after your edits.

        language_to_update : typing.Optional[Language]
            If hebrew_word_format included both 'en' and 'he' (and therefor, for the same word there is both an English and a Hebrew version),this specifies which language version of the timestamps to update. Must be either 'en' for English or 'he' for Hebrew timestamps.

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

        Returns
        -------
        typing.List[Timestamp]

        Examples
        --------
        from soferai import SoferAI
        from soferai.transcribe import Timestamp

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.timestamps.update_timestamps(
            old_timestamps=[
                Timestamp(
                    word="word",
                    start=1.1,
                    end=1.1,
                ),
                Timestamp(
                    word="word",
                    start=1.1,
                    end=1.1,
                ),
            ],
            edited_text="edited_text",
        )
        """
        _response = self._raw_client.update_timestamps(
            old_timestamps=old_timestamps,
            edited_text=edited_text,
            language_to_update=language_to_update,
            request_options=request_options,
        )
        return _response.data


class AsyncTimestampsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawTimestampsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawTimestampsClient
        """
        return self._raw_client

    async def outline(
        self,
        *,
        transcription_id: TranscriptionId,
        monotone: typing.Optional[bool] = OMIT,
        conclusion_bias: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[OutlineTopic]:
        """
        Outline of topics discussed by timestamp, generated end-to-end from a transcription ID.

        This endpoint will:
        1) Fetch the transcript and word-level timestamps for the given transcription
        2) Generate chapter topics (title + starting_phrase) using an LLM from the transcript text
        3) Align each topic's starting phrase to timestamps

        Parameters
        ----------
        transcription_id : TranscriptionId
            ID of the transcription to process end-to-end

        monotone : typing.Optional[bool]
            If true, each topic is searched after the previous topic's start (with a small backoff)

        conclusion_bias : typing.Optional[bool]
            If true and a title includes the word "conclusion", search in the last third of the audio

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

        Returns
        -------
        typing.List[OutlineTopic]

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

        from soferai import AsyncSoferAI

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


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


        asyncio.run(main())
        """
        _response = await self._raw_client.outline(
            transcription_id=transcription_id,
            monotone=monotone,
            conclusion_bias=conclusion_bias,
            request_options=request_options,
        )
        return _response.data

    async def update_timestamps(
        self,
        *,
        old_timestamps: typing.Sequence[Timestamp],
        edited_text: str,
        language_to_update: typing.Optional[Language] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[Timestamp]:
        """
        Update the timestamps based on edited text.

        Parameters
        ----------
        old_timestamps : typing.Sequence[Timestamp]
            The original timestamps associated with the text before editing. These will be used as reference points to align the new timestamps.

        edited_text : str
            The modified version of the transcription text that needs updated timestamp alignments. This should be the complete text after your edits.

        language_to_update : typing.Optional[Language]
            If hebrew_word_format included both 'en' and 'he' (and therefor, for the same word there is both an English and a Hebrew version),this specifies which language version of the timestamps to update. Must be either 'en' for English or 'he' for Hebrew timestamps.

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

        Returns
        -------
        typing.List[Timestamp]

        Examples
        --------
        import asyncio

        from soferai import AsyncSoferAI
        from soferai.transcribe import Timestamp

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.timestamps.update_timestamps(
                old_timestamps=[
                    Timestamp(
                        word="word",
                        start=1.1,
                        end=1.1,
                    ),
                    Timestamp(
                        word="word",
                        start=1.1,
                        end=1.1,
                    ),
                ],
                edited_text="edited_text",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_timestamps(
            old_timestamps=old_timestamps,
            edited_text=edited_text,
            language_to_update=language_to_update,
            request_options=request_options,
        )
        return _response.data
