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

import typing

from .... import core
from ....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ....core.request_options import RequestOptions
from ....types.media_id import MediaId
from ....types.order_id import OrderId
from ....types.order_media_response import OrderMediaResponse
from ....types.register_media_response import RegisterMediaResponse
from .raw_client import AsyncRawMediaClient, RawMediaClient

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


class MediaClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawMediaClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawMediaClient
        """
        return self._raw_client

    def register(
        self,
        order_id: OrderId,
        *,
        declared_language: str,
        media: typing.Optional[core.File] = OMIT,
        media_url: typing.Optional[str] = OMIT,
        media_url_filename: typing.Optional[str] = OMIT,
        media_url_content_type: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RegisterMediaResponse:
        """
        Registers a media file with an order, either by uploading it directly or by providing a URL to fetch it from. Exactly one of `media` or `media_url` must be provided. The registered media can then be referenced when adding order items.

        Parameters
        ----------
        order_id : OrderId
            The ID of the order to which this media will be attached.

        declared_language : str
            The language code of the media content (e.g. 'en', 'es-ES'). Must be a supported source language for some order item kind.

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

        media_url : typing.Optional[str]
            A URL to fetch the media file from. Mutually exclusive with media.

        media_url_filename : typing.Optional[str]
            The filename for URL-sourced media (e.g. 'example.mp4'). Required when using media_url.

        media_url_content_type : typing.Optional[str]
            The MIME type for URL-sourced media (e.g. 'video/mp4'). Required when using media_url.

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

        Returns
        -------
        RegisterMediaResponse
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.productions.orders.media.register(
            order_id="order_id",
            declared_language="declared_language",
        )
        """
        _response = self._raw_client.register(
            order_id,
            declared_language=declared_language,
            media=media,
            media_url=media_url,
            media_url_filename=media_url_filename,
            media_url_content_type=media_url_content_type,
            request_options=request_options,
        )
        return _response.data

    def get(
        self, order_id: OrderId, media_id: MediaId, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OrderMediaResponse:
        """
        Retrieves metadata and a time-limited download URL for a previously uploaded media file.

        Parameters
        ----------
        order_id : OrderId
            The ID of the order.

        media_id : MediaId
            The ID of the media file.

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

        Returns
        -------
        OrderMediaResponse
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.productions.orders.media.get(
            order_id="order_id",
            media_id="media_id",
        )
        """
        _response = self._raw_client.get(order_id, media_id, request_options=request_options)
        return _response.data


class AsyncMediaClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawMediaClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawMediaClient
        """
        return self._raw_client

    async def register(
        self,
        order_id: OrderId,
        *,
        declared_language: str,
        media: typing.Optional[core.File] = OMIT,
        media_url: typing.Optional[str] = OMIT,
        media_url_filename: typing.Optional[str] = OMIT,
        media_url_content_type: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RegisterMediaResponse:
        """
        Registers a media file with an order, either by uploading it directly or by providing a URL to fetch it from. Exactly one of `media` or `media_url` must be provided. The registered media can then be referenced when adding order items.

        Parameters
        ----------
        order_id : OrderId
            The ID of the order to which this media will be attached.

        declared_language : str
            The language code of the media content (e.g. 'en', 'es-ES'). Must be a supported source language for some order item kind.

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

        media_url : typing.Optional[str]
            A URL to fetch the media file from. Mutually exclusive with media.

        media_url_filename : typing.Optional[str]
            The filename for URL-sourced media (e.g. 'example.mp4'). Required when using media_url.

        media_url_content_type : typing.Optional[str]
            The MIME type for URL-sourced media (e.g. 'video/mp4'). Required when using media_url.

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

        Returns
        -------
        RegisterMediaResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.productions.orders.media.register(
                order_id="order_id",
                declared_language="declared_language",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.register(
            order_id,
            declared_language=declared_language,
            media=media,
            media_url=media_url,
            media_url_filename=media_url_filename,
            media_url_content_type=media_url_content_type,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self, order_id: OrderId, media_id: MediaId, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OrderMediaResponse:
        """
        Retrieves metadata and a time-limited download URL for a previously uploaded media file.

        Parameters
        ----------
        order_id : OrderId
            The ID of the order.

        media_id : MediaId
            The ID of the media file.

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

        Returns
        -------
        OrderMediaResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.productions.orders.media.get(
                order_id="order_id",
                media_id="media_id",
            )


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