# 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 .raw_client import AsyncRawUtilsClient, RawUtilsClient
from .types.duration_response import DurationResponse

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


class UtilsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawUtilsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawUtilsClient
        """
        return self._raw_client

    def get_duration(
        self,
        *,
        audio_url: typing.Optional[str] = OMIT,
        audio_file: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DurationResponse:
        """
        Returns the audio duration in seconds for a provided URL or base64-encoded file.

        Provide either `audio_url` or `audio_file` (base64). If both are provided, the request is invalid.

        Parameters
        ----------
        audio_url : typing.Optional[str]
            Direct URL to a downloadable audio file.

        audio_file : typing.Optional[str]
            Base64-encoded audio file content. Do not include a data URI prefix.

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

        Returns
        -------
        DurationResponse

        Examples
        --------
        from soferai import SoferAI

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.utils.get_duration()
        """
        _response = self._raw_client.get_duration(
            audio_url=audio_url, audio_file=audio_file, request_options=request_options
        )
        return _response.data


class AsyncUtilsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawUtilsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawUtilsClient
        """
        return self._raw_client

    async def get_duration(
        self,
        *,
        audio_url: typing.Optional[str] = OMIT,
        audio_file: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DurationResponse:
        """
        Returns the audio duration in seconds for a provided URL or base64-encoded file.

        Provide either `audio_url` or `audio_file` (base64). If both are provided, the request is invalid.

        Parameters
        ----------
        audio_url : typing.Optional[str]
            Direct URL to a downloadable audio file.

        audio_file : typing.Optional[str]
            Base64-encoded audio file content. Do not include a data URI prefix.

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

        Returns
        -------
        DurationResponse

        Examples
        --------
        import asyncio

        from soferai import AsyncSoferAI

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.utils.get_duration()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_duration(
            audio_url=audio_url, audio_file=audio_file, request_options=request_options
        )
        return _response.data
