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

from __future__ import annotations

import os
import typing

import httpx
from .core.api_error import ApiError
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .core.logging import LogConfig, Logger
from .environment import SmallestAIEnvironment

if typing.TYPE_CHECKING:
    from .atoms.client import AsyncAtomsClient, AtomsClient
    from .waves.client import AsyncWavesClient, WavesClient


class SmallestAI:
    """
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.

    Parameters
    ----------
    environment : SmallestAIEnvironment
        The environment to use for requests from the client. from .environment import SmallestAIEnvironment



        Defaults to SmallestAIEnvironment.PRODUCTION



    token : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
    headers : typing.Optional[typing.Dict[str, str]]
        Additional headers to send with every request.

    timeout : typing.Optional[float]
        The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

    follow_redirects : typing.Optional[bool]
        Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

    httpx_client : typing.Optional[httpx.Client]
        The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.

    logging : typing.Optional[typing.Union[LogConfig, Logger]]
        Configure logging for the SDK. Accepts a LogConfig dict with 'level' (debug/info/warn/error), 'logger' (custom logger implementation), and 'silent' (boolean, defaults to True) fields. You can also pass a pre-configured Logger instance.

    Examples
    --------
    from smallestai import SmallestAI

    client = SmallestAI(
        token="YOUR_TOKEN",
    )
    """

    def __init__(
        self,
        *,
        environment: SmallestAIEnvironment = SmallestAIEnvironment.PRODUCTION,
        token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("SMALLEST_AI_TOKEN"),
        headers: typing.Optional[typing.Dict[str, str]] = None,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.Client] = None,
        logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
    ):
        _defaulted_timeout = (
            timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
        )
        if token is None:
            raise ApiError(
                body="The client must be instantiated be either passing in token or setting SMALLEST_AI_TOKEN"
            )
        self._client_wrapper = SyncClientWrapper(
            environment=environment,
            token=token,
            headers=headers,
            httpx_client=httpx_client
            if httpx_client is not None
            else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
            if follow_redirects is not None
            else httpx.Client(timeout=_defaulted_timeout),
            timeout=_defaulted_timeout,
            logging=logging,
        )
        self._atoms: typing.Optional[AtomsClient] = None
        self._waves: typing.Optional[WavesClient] = None

    @property
    def atoms(self):
        if self._atoms is None:
            from .atoms.client import AtomsClient  # noqa: E402

            self._atoms = AtomsClient(client_wrapper=self._client_wrapper)
        return self._atoms

    @property
    def waves(self):
        if self._waves is None:
            from .waves.client import WavesClient  # noqa: E402

            self._waves = WavesClient(client_wrapper=self._client_wrapper)
        return self._waves


class AsyncSmallestAI:
    """
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.

    Parameters
    ----------
    environment : SmallestAIEnvironment
        The environment to use for requests from the client. from .environment import SmallestAIEnvironment



        Defaults to SmallestAIEnvironment.PRODUCTION



    token : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
    headers : typing.Optional[typing.Dict[str, str]]
        Additional headers to send with every request.

    timeout : typing.Optional[float]
        The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

    follow_redirects : typing.Optional[bool]
        Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

    httpx_client : typing.Optional[httpx.AsyncClient]
        The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.

    logging : typing.Optional[typing.Union[LogConfig, Logger]]
        Configure logging for the SDK. Accepts a LogConfig dict with 'level' (debug/info/warn/error), 'logger' (custom logger implementation), and 'silent' (boolean, defaults to True) fields. You can also pass a pre-configured Logger instance.

    Examples
    --------
    from smallestai import AsyncSmallestAI

    client = AsyncSmallestAI(
        token="YOUR_TOKEN",
    )
    """

    def __init__(
        self,
        *,
        environment: SmallestAIEnvironment = SmallestAIEnvironment.PRODUCTION,
        token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("SMALLEST_AI_TOKEN"),
        headers: typing.Optional[typing.Dict[str, str]] = None,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.AsyncClient] = None,
        logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
    ):
        _defaulted_timeout = (
            timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
        )
        if token is None:
            raise ApiError(
                body="The client must be instantiated be either passing in token or setting SMALLEST_AI_TOKEN"
            )
        self._client_wrapper = AsyncClientWrapper(
            environment=environment,
            token=token,
            headers=headers,
            httpx_client=httpx_client
            if httpx_client is not None
            else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
            if follow_redirects is not None
            else httpx.AsyncClient(timeout=_defaulted_timeout),
            timeout=_defaulted_timeout,
            logging=logging,
        )
        self._atoms: typing.Optional[AsyncAtomsClient] = None
        self._waves: typing.Optional[AsyncWavesClient] = None

    @property
    def atoms(self):
        if self._atoms is None:
            from .atoms.client import AsyncAtomsClient  # noqa: E402

            self._atoms = AsyncAtomsClient(client_wrapper=self._client_wrapper)
        return self._atoms

    @property
    def waves(self):
        if self._waves is None:
            from .waves.client import AsyncWavesClient  # noqa: E402

            self._waves = AsyncWavesClient(client_wrapper=self._client_wrapper)
        return self._waves
