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

from __future__ import annotations

import typing

from ... import core
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ...core.request_options import RequestOptions
from ...types.dubbing_project_list_response import DubbingProjectListResponse
from ...types.dubbing_project_response import DubbingProjectResponse
from .raw_client import AsyncRawProjectClient, RawProjectClient
from .types.project_create_request_model_id import ProjectCreateRequestModelId
from .types.project_list_request_sort_direction import ProjectListRequestSortDirection

if typing.TYPE_CHECKING:
    from .language.client import AsyncLanguageClient, LanguageClient
    from .transcript.client import AsyncTranscriptClient, TranscriptClient
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class ProjectClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawProjectClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._language: typing.Optional[LanguageClient] = None
        self._transcript: typing.Optional[TranscriptClient] = None

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

        Returns
        -------
        RawProjectClient
        """
        return self._raw_client

    def list(
        self,
        *,
        cursor: typing.Optional[str] = None,
        page_size: typing.Optional[int] = None,
        status: typing.Optional[str] = None,
        sort_direction: typing.Optional[ProjectListRequestSortDirection] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DubbingProjectListResponse:
        """
        List the workspace's dubbing projects (cursor-paginated).

        Parameters
        ----------
        cursor : typing.Optional[str]
            Pagination cursor from a previous response's next_cursor.

        page_size : typing.Optional[int]
            Number of projects per page (max 100).

        status : typing.Optional[str]
            Filter to projects in this status (preparing, ready, failed).

        sort_direction : typing.Optional[ProjectListRequestSortDirection]
            Sort by creation time (default 'DESCENDING').

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

        Returns
        -------
        DubbingProjectListResponse
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.dubbing.project.list(
            page_size=20,
        )
        """
        _response = self._raw_client.list(
            cursor=cursor,
            page_size=page_size,
            status=status,
            sort_direction=sort_direction,
            request_options=request_options,
        )
        return _response.data

    def create(
        self,
        *,
        file: typing.Optional[core.File] = OMIT,
        source_url: typing.Optional[str] = OMIT,
        reference: typing.Optional[str] = OMIT,
        source_language: typing.Optional[str] = OMIT,
        model_id: typing.Optional[ProjectCreateRequestModelId] = OMIT,
        keyterms: typing.Optional[typing.List[str]] = OMIT,
        webhook_ids: typing.Optional[typing.List[str]] = OMIT,
        target_language: typing.Optional[str] = OMIT,
        transcript: typing.Optional[core.File] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DubbingProjectResponse:
        """
        Create a dubbing project from an uploaded file or a source URL.

        Parameters
        ----------
        file : typing.Optional[core.File]
            See core.File for more documentation

        source_url : typing.Optional[str]
            Public URL to fetch the source media from. Provide this or file.

        reference : typing.Optional[str]
            Optional free-form string (max 500 characters) to identify the project on your end.

        source_language : typing.Optional[str]
            BCP-47 language tag of the source media; must be a language the transcription model supports. Any region or script subtag is ignored, since transcription is per-language. Omit to auto-detect.

        model_id : typing.Optional[ProjectCreateRequestModelId]
            Default dubbing model id ('dubbing_v1' or 'dubbing_v2') for the project's language targets; a target may override it. Omit to use the system default.

        keyterms : typing.Optional[typing.List[str]]
            Key terms to bias transcription/translation toward (e.g. product or brand names). At most 1000 terms; each term at most 50 characters and 5 words; the characters `<>{}[]\\` are not allowed.

        webhook_ids : typing.Optional[typing.List[str]]
            Ids of workspace webhooks to notify when this project becomes ready or fails, and when any of its languages completes or fails. At most 3; each must be a webhook configured in your workspace.

        target_language : typing.Optional[str]
            Optional shortcut: also create a language target in this BCP-47 language, queued to start once the project is ready. Must be a language the dubbing model supports, and a region-qualified tag must be one of the supported dialects.

        transcript : typing.Optional[core.File]
            See core.File for more documentation

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

        Returns
        -------
        DubbingProjectResponse
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.dubbing.project.create(
            source_url="https://example.com/promo.mp4",
            source_language="en",
            reference="Q3 marketing video",
        )
        """
        _response = self._raw_client.create(
            file=file,
            source_url=source_url,
            reference=reference,
            source_language=source_language,
            model_id=model_id,
            keyterms=keyterms,
            webhook_ids=webhook_ids,
            target_language=target_language,
            transcript=transcript,
            request_options=request_options,
        )
        return _response.data

    def get(
        self, project_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DubbingProjectResponse:
        """
        Full project detail, including its language target ids.

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

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

        Returns
        -------
        DubbingProjectResponse
            Successful Response

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

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

    def delete(self, project_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete a project and its language targets.

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

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

        Returns
        -------
        None

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

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

    @property
    def language(self):
        if self._language is None:
            from .language.client import LanguageClient  # noqa: E402

            self._language = LanguageClient(client_wrapper=self._client_wrapper)
        return self._language

    @property
    def transcript(self):
        if self._transcript is None:
            from .transcript.client import TranscriptClient  # noqa: E402

            self._transcript = TranscriptClient(client_wrapper=self._client_wrapper)
        return self._transcript


class AsyncProjectClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawProjectClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._language: typing.Optional[AsyncLanguageClient] = None
        self._transcript: typing.Optional[AsyncTranscriptClient] = None

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

        Returns
        -------
        AsyncRawProjectClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        cursor: typing.Optional[str] = None,
        page_size: typing.Optional[int] = None,
        status: typing.Optional[str] = None,
        sort_direction: typing.Optional[ProjectListRequestSortDirection] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DubbingProjectListResponse:
        """
        List the workspace's dubbing projects (cursor-paginated).

        Parameters
        ----------
        cursor : typing.Optional[str]
            Pagination cursor from a previous response's next_cursor.

        page_size : typing.Optional[int]
            Number of projects per page (max 100).

        status : typing.Optional[str]
            Filter to projects in this status (preparing, ready, failed).

        sort_direction : typing.Optional[ProjectListRequestSortDirection]
            Sort by creation time (default 'DESCENDING').

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

        Returns
        -------
        DubbingProjectListResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.dubbing.project.list(
                page_size=20,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            cursor=cursor,
            page_size=page_size,
            status=status,
            sort_direction=sort_direction,
            request_options=request_options,
        )
        return _response.data

    async def create(
        self,
        *,
        file: typing.Optional[core.File] = OMIT,
        source_url: typing.Optional[str] = OMIT,
        reference: typing.Optional[str] = OMIT,
        source_language: typing.Optional[str] = OMIT,
        model_id: typing.Optional[ProjectCreateRequestModelId] = OMIT,
        keyterms: typing.Optional[typing.List[str]] = OMIT,
        webhook_ids: typing.Optional[typing.List[str]] = OMIT,
        target_language: typing.Optional[str] = OMIT,
        transcript: typing.Optional[core.File] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DubbingProjectResponse:
        """
        Create a dubbing project from an uploaded file or a source URL.

        Parameters
        ----------
        file : typing.Optional[core.File]
            See core.File for more documentation

        source_url : typing.Optional[str]
            Public URL to fetch the source media from. Provide this or file.

        reference : typing.Optional[str]
            Optional free-form string (max 500 characters) to identify the project on your end.

        source_language : typing.Optional[str]
            BCP-47 language tag of the source media; must be a language the transcription model supports. Any region or script subtag is ignored, since transcription is per-language. Omit to auto-detect.

        model_id : typing.Optional[ProjectCreateRequestModelId]
            Default dubbing model id ('dubbing_v1' or 'dubbing_v2') for the project's language targets; a target may override it. Omit to use the system default.

        keyterms : typing.Optional[typing.List[str]]
            Key terms to bias transcription/translation toward (e.g. product or brand names). At most 1000 terms; each term at most 50 characters and 5 words; the characters `<>{}[]\\` are not allowed.

        webhook_ids : typing.Optional[typing.List[str]]
            Ids of workspace webhooks to notify when this project becomes ready or fails, and when any of its languages completes or fails. At most 3; each must be a webhook configured in your workspace.

        target_language : typing.Optional[str]
            Optional shortcut: also create a language target in this BCP-47 language, queued to start once the project is ready. Must be a language the dubbing model supports, and a region-qualified tag must be one of the supported dialects.

        transcript : typing.Optional[core.File]
            See core.File for more documentation

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

        Returns
        -------
        DubbingProjectResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.dubbing.project.create(
                source_url="https://example.com/promo.mp4",
                source_language="en",
                reference="Q3 marketing video",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            file=file,
            source_url=source_url,
            reference=reference,
            source_language=source_language,
            model_id=model_id,
            keyterms=keyterms,
            webhook_ids=webhook_ids,
            target_language=target_language,
            transcript=transcript,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self, project_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DubbingProjectResponse:
        """
        Full project detail, including its language target ids.

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

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

        Returns
        -------
        DubbingProjectResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.dubbing.project.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(self, project_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete a project and its language targets.

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

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


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


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

    @property
    def language(self):
        if self._language is None:
            from .language.client import AsyncLanguageClient  # noqa: E402

            self._language = AsyncLanguageClient(client_wrapper=self._client_wrapper)
        return self._language

    @property
    def transcript(self):
        if self._transcript is None:
            from .transcript.client import AsyncTranscriptClient  # noqa: E402

            self._transcript = AsyncTranscriptClient(client_wrapper=self._client_wrapper)
        return self._transcript
