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

from __future__ import annotations

import datetime as dt
import typing

from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ...core.request_options import RequestOptions
from ...types.create_order_request import CreateOrderRequest
from ...types.create_order_response import CreateOrderResponse
from ...types.list_orders_response import ListOrdersResponse
from ...types.order_id import OrderId
from ...types.order_response import OrderResponse
from ...types.order_state import OrderState
from ...types.submit_order_response import SubmitOrderResponse
from ...types.update_order_request import UpdateOrderRequest
from ...types.update_order_response import UpdateOrderResponse
from .raw_client import AsyncRawOrdersClient, RawOrdersClient

if typing.TYPE_CHECKING:
    from .deliverables.client import AsyncDeliverablesClient, DeliverablesClient
    from .items.client import AsyncItemsClient, ItemsClient
    from .languages.client import AsyncLanguagesClient, LanguagesClient
    from .media.client import AsyncMediaClient, MediaClient
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class OrdersClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawOrdersClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._media: typing.Optional[MediaClient] = None
        self._items: typing.Optional[ItemsClient] = None
        self._deliverables: typing.Optional[DeliverablesClient] = None
        self._languages: typing.Optional[LanguagesClient] = None

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

        Returns
        -------
        RawOrdersClient
        """
        return self._raw_client

    def list(
        self,
        *,
        page_size: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        status: typing.Optional[typing.Union[OrderState, typing.Sequence[OrderState]]] = None,
        start_date: typing.Optional[dt.datetime] = None,
        end_date: typing.Optional[dt.datetime] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListOrdersResponse:
        """
        Lists Productions orders in the workspace. Supports filtering by status and date range, with pagination.

        Parameters
        ----------
        page_size : typing.Optional[int]
            Maximum number of orders to return per page.

        offset : typing.Optional[int]
            Number of orders to skip for pagination.

        status : typing.Optional[typing.Union[OrderState, typing.Sequence[OrderState]]]
            Filter orders by one or more statuses.

        start_date : typing.Optional[dt.datetime]
            Filter orders created on or after this date.

        end_date : typing.Optional[dt.datetime]
            Filter orders created on or before this date.

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

        Returns
        -------
        ListOrdersResponse
            Successful Response

        Examples
        --------
        import datetime

        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.productions.orders.list(
            page_size=1,
            offset=1,
            status=["open"],
            start_date=datetime.datetime.fromisoformat(
                "2024-01-15 09:30:00+00:00",
            ),
            end_date=datetime.datetime.fromisoformat(
                "2024-01-15 09:30:00+00:00",
            ),
        )
        """
        _response = self._raw_client.list(
            page_size=page_size,
            offset=offset,
            status=status,
            start_date=start_date,
            end_date=end_date,
            request_options=request_options,
        )
        return _response.data

    def create(
        self,
        *,
        request: typing.Optional[CreateOrderRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateOrderResponse:
        """
        Creates a new Productions order in the workspace. The order starts in the open state and can be configured with items before submission.

        Parameters
        ----------
        request : typing.Optional[CreateOrderRequest]

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

        Returns
        -------
        CreateOrderResponse
            Successful Response

        Examples
        --------
        from elevenlabs import CreateOrderRequest, ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.productions.orders.create(
            request=CreateOrderRequest(
                sandbox=False,
            ),
        )
        """
        _response = self._raw_client.create(request=request, request_options=request_options)
        return _response.data

    def get(self, order_id: OrderId, *, request_options: typing.Optional[RequestOptions] = None) -> OrderResponse:
        """
        Retrieves full details for a Productions order.

        Quote and pricing information may not be available immediately; if you wish to see the quote before submission, you may need to poll the order details until it is ready.

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

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

        Returns
        -------
        OrderResponse
            Successful Response

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

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

    def update(
        self, order_id: OrderId, *, request: UpdateOrderRequest, request_options: typing.Optional[RequestOptions] = None
    ) -> UpdateOrderResponse:
        """
        Updates an open order.

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

        request : UpdateOrderRequest

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

        Returns
        -------
        UpdateOrderResponse
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs, UpdateOrderRequest

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.productions.orders.update(
            order_id="order_id",
            request=UpdateOrderRequest(
                name="Spanish Dubs",
            ),
        )
        """
        _response = self._raw_client.update(order_id, request=request, request_options=request_options)
        return _response.data

    def submit(
        self, order_id: OrderId, *, request_options: typing.Optional[RequestOptions] = None
    ) -> SubmitOrderResponse:
        """
        Submits an open order for processing. The order must have at least one item. Once submitted, items can no longer be modified.

        Upon submission, the workspace will be charged for the order. The quote is based on information extracted from the uploaded media, such as its duration. The quote may not be available immediately; if you wish to see the quote before submission, you may need to poll the order details until the quote is ready.

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

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

        Returns
        -------
        SubmitOrderResponse
            Successful Response

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

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

    @property
    def media(self):
        if self._media is None:
            from .media.client import MediaClient  # noqa: E402

            self._media = MediaClient(client_wrapper=self._client_wrapper)
        return self._media

    @property
    def items(self):
        if self._items is None:
            from .items.client import ItemsClient  # noqa: E402

            self._items = ItemsClient(client_wrapper=self._client_wrapper)
        return self._items

    @property
    def deliverables(self):
        if self._deliverables is None:
            from .deliverables.client import DeliverablesClient  # noqa: E402

            self._deliverables = DeliverablesClient(client_wrapper=self._client_wrapper)
        return self._deliverables

    @property
    def languages(self):
        if self._languages is None:
            from .languages.client import LanguagesClient  # noqa: E402

            self._languages = LanguagesClient(client_wrapper=self._client_wrapper)
        return self._languages


class AsyncOrdersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawOrdersClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._media: typing.Optional[AsyncMediaClient] = None
        self._items: typing.Optional[AsyncItemsClient] = None
        self._deliverables: typing.Optional[AsyncDeliverablesClient] = None
        self._languages: typing.Optional[AsyncLanguagesClient] = None

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

        Returns
        -------
        AsyncRawOrdersClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        page_size: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        status: typing.Optional[typing.Union[OrderState, typing.Sequence[OrderState]]] = None,
        start_date: typing.Optional[dt.datetime] = None,
        end_date: typing.Optional[dt.datetime] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListOrdersResponse:
        """
        Lists Productions orders in the workspace. Supports filtering by status and date range, with pagination.

        Parameters
        ----------
        page_size : typing.Optional[int]
            Maximum number of orders to return per page.

        offset : typing.Optional[int]
            Number of orders to skip for pagination.

        status : typing.Optional[typing.Union[OrderState, typing.Sequence[OrderState]]]
            Filter orders by one or more statuses.

        start_date : typing.Optional[dt.datetime]
            Filter orders created on or after this date.

        end_date : typing.Optional[dt.datetime]
            Filter orders created on or before this date.

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

        Returns
        -------
        ListOrdersResponse
            Successful Response

        Examples
        --------
        import asyncio
        import datetime

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.productions.orders.list(
                page_size=1,
                offset=1,
                status=["open"],
                start_date=datetime.datetime.fromisoformat(
                    "2024-01-15 09:30:00+00:00",
                ),
                end_date=datetime.datetime.fromisoformat(
                    "2024-01-15 09:30:00+00:00",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            page_size=page_size,
            offset=offset,
            status=status,
            start_date=start_date,
            end_date=end_date,
            request_options=request_options,
        )
        return _response.data

    async def create(
        self,
        *,
        request: typing.Optional[CreateOrderRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateOrderResponse:
        """
        Creates a new Productions order in the workspace. The order starts in the open state and can be configured with items before submission.

        Parameters
        ----------
        request : typing.Optional[CreateOrderRequest]

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

        Returns
        -------
        CreateOrderResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs, CreateOrderRequest

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.productions.orders.create(
                request=CreateOrderRequest(
                    sandbox=False,
                ),
            )


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

    async def get(self, order_id: OrderId, *, request_options: typing.Optional[RequestOptions] = None) -> OrderResponse:
        """
        Retrieves full details for a Productions order.

        Quote and pricing information may not be available immediately; if you wish to see the quote before submission, you may need to poll the order details until it is ready.

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

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

        Returns
        -------
        OrderResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


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


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

    async def update(
        self, order_id: OrderId, *, request: UpdateOrderRequest, request_options: typing.Optional[RequestOptions] = None
    ) -> UpdateOrderResponse:
        """
        Updates an open order.

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

        request : UpdateOrderRequest

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

        Returns
        -------
        UpdateOrderResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs, UpdateOrderRequest

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.productions.orders.update(
                order_id="order_id",
                request=UpdateOrderRequest(
                    name="Spanish Dubs",
                ),
            )


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

    async def submit(
        self, order_id: OrderId, *, request_options: typing.Optional[RequestOptions] = None
    ) -> SubmitOrderResponse:
        """
        Submits an open order for processing. The order must have at least one item. Once submitted, items can no longer be modified.

        Upon submission, the workspace will be charged for the order. The quote is based on information extracted from the uploaded media, such as its duration. The quote may not be available immediately; if you wish to see the quote before submission, you may need to poll the order details until the quote is ready.

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

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

        Returns
        -------
        SubmitOrderResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


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


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

    @property
    def media(self):
        if self._media is None:
            from .media.client import AsyncMediaClient  # noqa: E402

            self._media = AsyncMediaClient(client_wrapper=self._client_wrapper)
        return self._media

    @property
    def items(self):
        if self._items is None:
            from .items.client import AsyncItemsClient  # noqa: E402

            self._items = AsyncItemsClient(client_wrapper=self._client_wrapper)
        return self._items

    @property
    def deliverables(self):
        if self._deliverables is None:
            from .deliverables.client import AsyncDeliverablesClient  # noqa: E402

            self._deliverables = AsyncDeliverablesClient(client_wrapper=self._client_wrapper)
        return self._deliverables

    @property
    def languages(self):
        if self._languages is None:
            from .languages.client import AsyncLanguagesClient  # noqa: E402

            self._languages = AsyncLanguagesClient(client_wrapper=self._client_wrapper)
        return self._languages
