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

import typing

import httpx
import os

from .core.api_error import ApiError
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .environment import ElevenLabsEnvironment
from .resources.audio_native.client import AsyncAudioNativeClient, AudioNativeClient
from .resources.history.client import AsyncHistoryClient, HistoryClient
from .resources.models.client import AsyncModelsClient, ModelsClient
from .resources.projects.client import AsyncProjectsClient, ProjectsClient
from .resources.pronunciation_dictionary.client import AsyncPronunciationDictionaryClient, PronunciationDictionaryClient
from .resources.samples.client import AsyncSamplesClient, SamplesClient
from .resources.text_to_speech.client import AsyncTextToSpeechClient, TextToSpeechClient
from .resources.user.client import AsyncUserClient, UserClient
from .resources.voices.client import AsyncVoicesClient, VoicesClient


class ElevenLabs:
    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: ElevenLabsEnvironment = ElevenLabsEnvironment.PRODUCTION,
        api_key: typing.Optional[str] = os.getenv("ELEVEN_API_KEY"),
        timeout: typing.Optional[float] = 60,
        httpx_client: typing.Optional[httpx.Client] = None
    ):
        """
        Args:
            base_url typing.Optional[str]. Override the base URL.
            environment ElevenLabsEnvironment. Defaults to PRODUCTION.
            api_key typing.Optional[str]. Defaults to ELEVEN_API_KEY environment variable.
            timeout typing.Optional[float]. Defaults to 60 seconds.
            httpx_client typing.Optional[httpx.AsyncClient]. Override the httpx client.
        """
        self._client_wrapper = SyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            xi_api_key=api_key,
            httpx_client=httpx.Client(timeout=timeout) if httpx_client is None else httpx_client,
        )
        self.history = HistoryClient(client_wrapper=self._client_wrapper)
        self.samples = SamplesClient(client_wrapper=self._client_wrapper)
        self.text_to_speech = TextToSpeechClient(client_wrapper=self._client_wrapper)
        self.user = UserClient(client_wrapper=self._client_wrapper)
        self.voices = VoicesClient(client_wrapper=self._client_wrapper)
        self.projects = ProjectsClient(client_wrapper=self._client_wrapper)
        self.models = ModelsClient(client_wrapper=self._client_wrapper)
        self.audio_native = AudioNativeClient(client_wrapper=self._client_wrapper)
        self.pronunciation_dictionary = PronunciationDictionaryClient(client_wrapper=self._client_wrapper)


class AsyncElevenLabs:
    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: ElevenLabsEnvironment = ElevenLabsEnvironment.PRODUCTION,
        api_key: typing.Optional[str] = os.getenv("ELEVEN_API_KEY"),
        timeout: typing.Optional[float] = 60,
        httpx_client: typing.Optional[httpx.AsyncClient] = None
    ):  
        """
        Args:
            base_url typing.Optional[str]. Override the base URL.
            environment ElevenLabsEnvironment. Defaults to PRODUCTION.
            api_key typing.Optional[str]. Defaults to ELEVEN_API_KEY environment variable.
            timeout typing.Optional[float]. Defaults to 60 seconds.
            httpx_client typing.Optional[httpx.AsyncClient]. Override the httpx client.
        """
        self._client_wrapper = AsyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            xi_api_key=api_key,
            httpx_client=httpx.AsyncClient(timeout=timeout) if httpx_client is None else httpx_client,
        )
        self.history = AsyncHistoryClient(client_wrapper=self._client_wrapper)
        self.samples = AsyncSamplesClient(client_wrapper=self._client_wrapper)
        self.text_to_speech = AsyncTextToSpeechClient(client_wrapper=self._client_wrapper)
        self.user = AsyncUserClient(client_wrapper=self._client_wrapper)
        self.voices = AsyncVoicesClient(client_wrapper=self._client_wrapper)
        self.projects = AsyncProjectsClient(client_wrapper=self._client_wrapper)
        self.models = AsyncModelsClient(client_wrapper=self._client_wrapper)
        self.audio_native = AsyncAudioNativeClient(client_wrapper=self._client_wrapper)
        self.pronunciation_dictionary = AsyncPronunciationDictionaryClient(client_wrapper=self._client_wrapper)


def _get_base_url(*, base_url: typing.Optional[str] = None, environment: ElevenLabsEnvironment) -> str:
    if base_url is not None:
        return base_url
    elif environment is not None:
        return environment.value
    else:
        raise Exception("Please pass in either base_url or environment to construct the client")
