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

import os
import typing

import httpx

from .api_keys.client import ApiKeysClient, AsyncApiKeysClient
from .app_clients.client import AppClientsClient, AsyncAppClientsClient
from .auth.client import AsyncAuthClient, AuthClient
from .chats.client import AsyncChatsClient, ChatsClient
from .core.api_error import ApiError
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .core.oauth_token_provider import OAuthTokenProvider
from .corpora.client import AsyncCorporaClient, CorporaClient
from .documents.client import AsyncDocumentsClient, DocumentsClient
from .encoders.client import AsyncEncodersClient, EncodersClient
from .environment import VectaraEnvironment
from .jobs.client import AsyncJobsClient, JobsClient
from .large_language_models.client import AsyncLargeLanguageModelsClient, LargeLanguageModelsClient
from .queries.client import AsyncQueriesClient, QueriesClient
from .rerankers.client import AsyncRerankersClient, RerankersClient
from .upload.client import AsyncUploadClient, UploadClient
from .users.client import AsyncUsersClient, UsersClient


class Vectara:
    """
    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
    ----------
    base_url : typing.Optional[str]
        The base url to use for requests from the client.

    environment : VectaraEnvironment
        The environment to use for requests from the client. from .environment import VectaraEnvironment
        Defaults to VectaraEnvironment.PRODUCTION

    api_key : typing.Optional[str]

    client_id : typing.Optional[str]

    client_secret : typing.Optional[str]

    _token_getter_override : typing.Optional[typing.Callable[[], str]]
    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.

    Examples
    --------
    from vectara.client import Vectara

    client = Vectara(
        api_key="YOUR_API_KEY",
        client_id="YOUR_CLIENT_ID",
        client_secret="YOUR_CLIENT_SECRET",
    )
    """

    def __init__(
        self,
        *,
        environment: VectaraEnvironment = VectaraEnvironment.PRODUCTION,
        api_key: typing.Optional[str] = os.getenv("VECTARA_API_KEY"),
        client_id: typing.Optional[str] = os.getenv("VECTARA_CLIENT_ID"),
        client_secret: typing.Optional[str] = os.getenv("VECTARA_CLIENT_SECRET"),
        _token_getter_override: typing.Optional[typing.Callable[[], str]] = None,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.Client] = None
    ):
        _defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
        if api_key is not None:
            self._client_wrapper = SyncClientWrapper(
                environment=environment,
                api_key=api_key,
                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,
            )            
        elif client_id is not None and client_secret is not None: 
            oauth_token_provider = OAuthTokenProvider(
                client_id=client_id,
                client_secret=client_secret,
                client_wrapper=SyncClientWrapper(
                    environment=environment,
                    api_key=api_key,
                    httpx_client=httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
                    if follow_redirects is not None
                    else httpx.Client(timeout=_defaulted_timeout),
                    timeout=_defaulted_timeout,
                ),
            )
            self._client_wrapper = SyncClientWrapper(
                environment=environment,
                api_key=api_key,
                token=_token_getter_override if _token_getter_override is not None else oauth_token_provider.get_token,
                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,
            )
        else: 
            raise ApiError(
                body="The client must be instantiated be either passing in api_key, client_id or client_secret"
            )      
        self.api_keys = ApiKeysClient(client_wrapper=self._client_wrapper)
        self.app_clients = AppClientsClient(client_wrapper=self._client_wrapper)
        self.auth = AuthClient(client_wrapper=self._client_wrapper)
        self.chats = ChatsClient(client_wrapper=self._client_wrapper)
        self.corpora = CorporaClient(client_wrapper=self._client_wrapper)
        self.documents = DocumentsClient(client_wrapper=self._client_wrapper)
        self.encoders = EncodersClient(client_wrapper=self._client_wrapper)
        self.jobs = JobsClient(client_wrapper=self._client_wrapper)
        self.large_language_models = LargeLanguageModelsClient(client_wrapper=self._client_wrapper)
        self.queries = QueriesClient(client_wrapper=self._client_wrapper)
        self.rerankers = RerankersClient(client_wrapper=self._client_wrapper)
        self.upload = UploadClient(client_wrapper=self._client_wrapper)
        self.users = UsersClient(client_wrapper=self._client_wrapper)


class AsyncVectara:
    """
    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
    ----------
    base_url : typing.Optional[str]
        The base url to use for requests from the client.

    environment : VectaraEnvironment
        The environment to use for requests from the client. from .environment import VectaraEnvironment
        Defaults to VectaraEnvironment.PRODUCTION

    api_key : typing.Optional[str]

    client_id : typing.Optional[str]

    client_secret : typing.Optional[str]

    _token_getter_override : typing.Optional[typing.Callable[[], str]]

    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.

    Examples
    --------
    from vectara.client import AsyncVectara

    client = AsyncVectara(
        api_key="YOUR_API_KEY",
        client_id="YOUR_CLIENT_ID",
        client_secret="YOUR_CLIENT_SECRET",
    )
    """

    def __init__(
        self,
        *,
        environment: VectaraEnvironment = VectaraEnvironment.PRODUCTION,
        api_key: typing.Optional[str] = os.getenv("VECTARA_API_KEY"),
        client_id: typing.Optional[str] = os.getenv("VECTARA_CLIENT_ID"),
        client_secret: typing.Optional[str] = os.getenv("VECTARA_CLIENT_SECRET"),
        _token_getter_override: typing.Optional[typing.Callable[[], str]] = None,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.AsyncClient] = None
    ):
        _defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None   
        if api_key is not None: 
            self._client_wrapper = AsyncClientWrapper(
                environment=environment,
                api_key=api_key,
                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,
            )
        elif client_id is not None and client_secret is not None: 
            oauth_token_provider = OAuthTokenProvider(
                client_id=client_id,
                client_secret=client_secret,
                client_wrapper=SyncClientWrapper(
                    environment=environment,
                    api_key=api_key,
                    httpx_client=httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
                    if follow_redirects is not None
                    else httpx.Client(timeout=_defaulted_timeout),
                    timeout=_defaulted_timeout,
                ),
            )
            self._client_wrapper = AsyncClientWrapper(
                environment=environment,
                api_key=api_key,
                token=_token_getter_override if _token_getter_override is not None else oauth_token_provider.get_token,
                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,
            )
        else: 
            raise ApiError(
                body="The client must be instantiated be either passing in api_key, client_id or client_secret"
            )      
        self.api_keys = AsyncApiKeysClient(client_wrapper=self._client_wrapper)
        self.app_clients = AsyncAppClientsClient(client_wrapper=self._client_wrapper)
        self.auth = AsyncAuthClient(client_wrapper=self._client_wrapper)
        self.chats = AsyncChatsClient(client_wrapper=self._client_wrapper)
        self.corpora = AsyncCorporaClient(client_wrapper=self._client_wrapper)
        self.documents = AsyncDocumentsClient(client_wrapper=self._client_wrapper)
        self.encoders = AsyncEncodersClient(client_wrapper=self._client_wrapper)
        self.jobs = AsyncJobsClient(client_wrapper=self._client_wrapper)
        self.large_language_models = AsyncLargeLanguageModelsClient(client_wrapper=self._client_wrapper)
        self.queries = AsyncQueriesClient(client_wrapper=self._client_wrapper)
        self.rerankers = AsyncRerankersClient(client_wrapper=self._client_wrapper)
        self.upload = AsyncUploadClient(client_wrapper=self._client_wrapper)
        self.users = AsyncUsersClient(client_wrapper=self._client_wrapper)
