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

import typing

import httpx

from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .environment import PetstoreApiEnvironment
from .resources.pet.client import AsyncPetClient, PetClient
from .resources.store.client import AsyncStoreClient, StoreClient
from .resources.user.client import AsyncUserClient, UserClient


class PetstoreApi:
    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: PetstoreApiEnvironment = PetstoreApiEnvironment.DEFAULT,
        api_key: str,
        token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
        timeout: typing.Optional[float] = 60,
        httpx_client: typing.Optional[httpx.Client] = None
    ):
        self._client_wrapper = SyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            api_key=api_key,
            token=token,
            httpx_client=httpx.Client(timeout=timeout) if httpx_client is None else httpx_client,
        )
        self.pet = PetClient(client_wrapper=self._client_wrapper)
        self.store = StoreClient(client_wrapper=self._client_wrapper)
        self.user = UserClient(client_wrapper=self._client_wrapper)


class AsyncPetstoreApi:
    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: PetstoreApiEnvironment = PetstoreApiEnvironment.DEFAULT,
        api_key: str,
        token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
        timeout: typing.Optional[float] = 60,
        httpx_client: typing.Optional[httpx.AsyncClient] = None
    ):
        self._client_wrapper = AsyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            api_key=api_key,
            token=token,
            httpx_client=httpx.AsyncClient(timeout=timeout) if httpx_client is None else httpx_client,
        )
        self.pet = AsyncPetClient(client_wrapper=self._client_wrapper)
        self.store = AsyncStoreClient(client_wrapper=self._client_wrapper)
        self.user = AsyncUserClient(client_wrapper=self._client_wrapper)


def _get_base_url(*, base_url: typing.Optional[str] = None, environment: PetstoreApiEnvironment) -> 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")
