# 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.dubbing_bulk_source_segment_update_response import DubbingBulkSourceSegmentUpdateResponse
from ....types.dubbing_segment_update_request import DubbingSegmentUpdateRequest
from ....types.dubbing_source_segment_update_response import DubbingSourceSegmentUpdateResponse
from ....types.dubbing_source_transcript_response import DubbingSourceTranscriptResponse
from ....types.dubbing_transcript_revision_response import DubbingTranscriptRevisionResponse
from .raw_client import AsyncRawTranscriptClient, RawTranscriptClient

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


class TranscriptClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawTranscriptClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawTranscriptClient
        """
        return self._raw_client

    def get(
        self, project_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DubbingSourceTranscriptResponse:
        """
        The project's source transcript, as editable segments.

        Parameters
        ----------
        project_id : str
            Identifier of the dubbing project.

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

        Returns
        -------
        DubbingSourceTranscriptResponse
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.dubbing.project.transcript.get(
            project_id="proj_1601kwkyxp0hfzvtmyxwqxx6mcy3",
        )
        """
        _response = self._raw_client.get(project_id, request_options=request_options)
        return _response.data

    def delete_segment(
        self, project_id: str, segment_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DubbingTranscriptRevisionResponse:
        """
        Enterprise only. Remove a source segment from the transcript.

        Parameters
        ----------
        project_id : str
            Identifier of the dubbing project.

        segment_id : str
            Identifier of the segment to remove.

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

        Returns
        -------
        DubbingTranscriptRevisionResponse
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.dubbing.project.transcript.delete_segment(
            project_id="proj_1601kwkyxp0hfzvtmyxwqxx6mcy3",
            segment_id="0199a3f0-1c2d-7abc-8def-0123456789ab",
        )
        """
        _response = self._raw_client.delete_segment(project_id, segment_id, request_options=request_options)
        return _response.data

    def update_segment(
        self,
        project_id: str,
        segment_id: str,
        *,
        request: DubbingSegmentUpdateRequest,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DubbingSourceSegmentUpdateResponse:
        """
        Enterprise only. Edit a source segment's text, speaker, or timing.

        Parameters
        ----------
        project_id : str
            Identifier of the dubbing project.

        segment_id : str
            Identifier of the segment to edit.

        request : DubbingSegmentUpdateRequest

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

        Returns
        -------
        DubbingSourceSegmentUpdateResponse
            Successful Response

        Examples
        --------
        from elevenlabs import DubbingSegmentUpdateRequest, ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.dubbing.project.transcript.update_segment(
            project_id="proj_1601kwkyxp0hfzvtmyxwqxx6mcy3",
            segment_id="0199a3f0-1c2d-7abc-8def-0123456789ab",
            request=DubbingSegmentUpdateRequest(
                text="Welcome to our latest product demo.",
            ),
        )
        """
        _response = self._raw_client.update_segment(
            project_id, segment_id, request=request, request_options=request_options
        )
        return _response.data

    def update_segments(
        self,
        project_id: str,
        *,
        segments: typing.Dict[str, DubbingSegmentUpdateRequest],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DubbingBulkSourceSegmentUpdateResponse:
        """
        Enterprise only. Edit several source segments' text, speaker, or timing in one atomic request.

        Parameters
        ----------
        project_id : str
            Identifier of the dubbing project.

        segments : typing.Dict[str, DubbingSegmentUpdateRequest]
            Map of segment id to the partial update to apply to that segment.

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

        Returns
        -------
        DubbingBulkSourceSegmentUpdateResponse
            Successful Response

        Examples
        --------
        from elevenlabs import DubbingSegmentUpdateRequest, ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.dubbing.project.transcript.update_segments(
            project_id="proj_1601kwkyxp0hfzvtmyxwqxx6mcy3",
            segments={
                "0199a3f0-1c2d-7abc-8def-0123456789ab": DubbingSegmentUpdateRequest(
                    text="Welcome to our latest product demo.",
                ),
                "0199a3f0-3e4f-7abc-8def-0123456789cd": DubbingSegmentUpdateRequest(
                    speaker_id="narrator",
                ),
            },
        )
        """
        _response = self._raw_client.update_segments(project_id, segments=segments, request_options=request_options)
        return _response.data

    def create_segment(
        self,
        project_id: str,
        *,
        text: str,
        speaker_id: str,
        start_s: float,
        end_s: float,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DubbingSourceSegmentUpdateResponse:
        """
        Enterprise only. Add a new source segment to the transcript.

        Parameters
        ----------
        project_id : str
            Identifier of the dubbing project.

        text : str
            The text of the new segment.

        speaker_id : str
            Identifier of the segment's speaker.

        start_s : float
            Start time of the segment, in seconds.

        end_s : float
            End time of the segment, in seconds.

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

        Returns
        -------
        DubbingSourceSegmentUpdateResponse
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.dubbing.project.transcript.create_segment(
            project_id="proj_1601kwkyxp0hfzvtmyxwqxx6mcy3",
            text="Thanks for watching.",
            speaker_id="default_speaker",
            start_s=42.0,
            end_s=44.0,
        )
        """
        _response = self._raw_client.create_segment(
            project_id, text=text, speaker_id=speaker_id, start_s=start_s, end_s=end_s, request_options=request_options
        )
        return _response.data


class AsyncTranscriptClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawTranscriptClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawTranscriptClient
        """
        return self._raw_client

    async def get(
        self, project_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DubbingSourceTranscriptResponse:
        """
        The project's source transcript, as editable segments.

        Parameters
        ----------
        project_id : str
            Identifier of the dubbing project.

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

        Returns
        -------
        DubbingSourceTranscriptResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.dubbing.project.transcript.get(
                project_id="proj_1601kwkyxp0hfzvtmyxwqxx6mcy3",
            )


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

    async def delete_segment(
        self, project_id: str, segment_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DubbingTranscriptRevisionResponse:
        """
        Enterprise only. Remove a source segment from the transcript.

        Parameters
        ----------
        project_id : str
            Identifier of the dubbing project.

        segment_id : str
            Identifier of the segment to remove.

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

        Returns
        -------
        DubbingTranscriptRevisionResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.dubbing.project.transcript.delete_segment(
                project_id="proj_1601kwkyxp0hfzvtmyxwqxx6mcy3",
                segment_id="0199a3f0-1c2d-7abc-8def-0123456789ab",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_segment(project_id, segment_id, request_options=request_options)
        return _response.data

    async def update_segment(
        self,
        project_id: str,
        segment_id: str,
        *,
        request: DubbingSegmentUpdateRequest,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DubbingSourceSegmentUpdateResponse:
        """
        Enterprise only. Edit a source segment's text, speaker, or timing.

        Parameters
        ----------
        project_id : str
            Identifier of the dubbing project.

        segment_id : str
            Identifier of the segment to edit.

        request : DubbingSegmentUpdateRequest

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

        Returns
        -------
        DubbingSourceSegmentUpdateResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs, DubbingSegmentUpdateRequest

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.dubbing.project.transcript.update_segment(
                project_id="proj_1601kwkyxp0hfzvtmyxwqxx6mcy3",
                segment_id="0199a3f0-1c2d-7abc-8def-0123456789ab",
                request=DubbingSegmentUpdateRequest(
                    text="Welcome to our latest product demo.",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_segment(
            project_id, segment_id, request=request, request_options=request_options
        )
        return _response.data

    async def update_segments(
        self,
        project_id: str,
        *,
        segments: typing.Dict[str, DubbingSegmentUpdateRequest],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DubbingBulkSourceSegmentUpdateResponse:
        """
        Enterprise only. Edit several source segments' text, speaker, or timing in one atomic request.

        Parameters
        ----------
        project_id : str
            Identifier of the dubbing project.

        segments : typing.Dict[str, DubbingSegmentUpdateRequest]
            Map of segment id to the partial update to apply to that segment.

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

        Returns
        -------
        DubbingBulkSourceSegmentUpdateResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs, DubbingSegmentUpdateRequest

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.dubbing.project.transcript.update_segments(
                project_id="proj_1601kwkyxp0hfzvtmyxwqxx6mcy3",
                segments={
                    "0199a3f0-1c2d-7abc-8def-0123456789ab": DubbingSegmentUpdateRequest(
                        text="Welcome to our latest product demo.",
                    ),
                    "0199a3f0-3e4f-7abc-8def-0123456789cd": DubbingSegmentUpdateRequest(
                        speaker_id="narrator",
                    ),
                },
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_segments(
            project_id, segments=segments, request_options=request_options
        )
        return _response.data

    async def create_segment(
        self,
        project_id: str,
        *,
        text: str,
        speaker_id: str,
        start_s: float,
        end_s: float,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DubbingSourceSegmentUpdateResponse:
        """
        Enterprise only. Add a new source segment to the transcript.

        Parameters
        ----------
        project_id : str
            Identifier of the dubbing project.

        text : str
            The text of the new segment.

        speaker_id : str
            Identifier of the segment's speaker.

        start_s : float
            Start time of the segment, in seconds.

        end_s : float
            End time of the segment, in seconds.

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

        Returns
        -------
        DubbingSourceSegmentUpdateResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.dubbing.project.transcript.create_segment(
                project_id="proj_1601kwkyxp0hfzvtmyxwqxx6mcy3",
                text="Thanks for watching.",
                speaker_id="default_speaker",
                start_s=42.0,
                end_s=44.0,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_segment(
            project_id, text=text, speaker_id=speaker_id, start_s=start_s, end_s=end_s, request_options=request_options
        )
        return _response.data
