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

import typing

import httpx
from . import core
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .core.logging import LogConfig, Logger
from .core.request_options import RequestOptions
from .environment import ConcreteApiEnvironment
from .raw_client import AsyncRawConcreteApi, RawConcreteApi
from .types.health_status import HealthStatus
from .types.upload_response import UploadResponse
from .types.vector_update_response import VectorUpdateResponse

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


class ConcreteApi:
    """
    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 : ConcreteApiEnvironment
        The environment to use for requests from the client. from .environment import ConcreteApiEnvironment



        Defaults to ConcreteApiEnvironment.DEFAULT



    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 concrete import ConcreteApi

    client = ConcreteApi()
    """

    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: ConcreteApiEnvironment = ConcreteApiEnvironment.DEFAULT,
        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
        )
        self._client_wrapper = SyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            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._raw_client = RawConcreteApi(client_wrapper=self._client_wrapper)

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

        Returns
        -------
        RawConcreteApi
        """
        return self._raw_client

    def get_health(self, *, request_options: typing.Optional[RequestOptions] = None) -> HealthStatus:
        """
        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HealthStatus
            OK

        Examples
        --------
        from concrete import ConcreteApi

        client = ConcreteApi()
        client.get_health()
        """
        _response = self._raw_client.get_health(request_options=request_options)
        return _response.data

    def upload_file(
        self,
        *,
        file: typing.Optional[core.File] = OMIT,
        metadata: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UploadResponse:
        """
        Parameters
        ----------
        file : typing.Optional[core.File]
            See core.File for more documentation

        metadata : typing.Optional[str]
            Optional JSON metadata associated with the file

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

        Returns
        -------
        UploadResponse
            File successfully uploaded

        Examples
        --------
        from concrete import ConcreteApi

        client = ConcreteApi()
        client.upload_file()
        """
        _response = self._raw_client.upload_file(file=file, metadata=metadata, request_options=request_options)
        return _response.data

    def start_vector_update(self, *, request_options: typing.Optional[RequestOptions] = None) -> VectorUpdateResponse:
        """
        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        VectorUpdateResponse
            Vector update started successfully

        Examples
        --------
        from concrete import ConcreteApi

        client = ConcreteApi()
        client.start_vector_update()
        """
        _response = self._raw_client.start_vector_update(request_options=request_options)
        return _response.data


class AsyncConcreteApi:
    """
    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 : ConcreteApiEnvironment
        The environment to use for requests from the client. from .environment import ConcreteApiEnvironment



        Defaults to ConcreteApiEnvironment.DEFAULT



    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 concrete import AsyncConcreteApi

    client = AsyncConcreteApi()
    """

    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: ConcreteApiEnvironment = ConcreteApiEnvironment.DEFAULT,
        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
        )
        self._client_wrapper = AsyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            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._raw_client = AsyncRawConcreteApi(client_wrapper=self._client_wrapper)

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

        Returns
        -------
        AsyncRawConcreteApi
        """
        return self._raw_client

    async def get_health(self, *, request_options: typing.Optional[RequestOptions] = None) -> HealthStatus:
        """
        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HealthStatus
            OK

        Examples
        --------
        import asyncio

        from concrete import AsyncConcreteApi

        client = AsyncConcreteApi()


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


        asyncio.run(main())
        """
        _response = await self._raw_client.get_health(request_options=request_options)
        return _response.data

    async def upload_file(
        self,
        *,
        file: typing.Optional[core.File] = OMIT,
        metadata: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UploadResponse:
        """
        Parameters
        ----------
        file : typing.Optional[core.File]
            See core.File for more documentation

        metadata : typing.Optional[str]
            Optional JSON metadata associated with the file

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

        Returns
        -------
        UploadResponse
            File successfully uploaded

        Examples
        --------
        import asyncio

        from concrete import AsyncConcreteApi

        client = AsyncConcreteApi()


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


        asyncio.run(main())
        """
        _response = await self._raw_client.upload_file(file=file, metadata=metadata, request_options=request_options)
        return _response.data

    async def start_vector_update(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> VectorUpdateResponse:
        """
        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        VectorUpdateResponse
            Vector update started successfully

        Examples
        --------
        import asyncio

        from concrete import AsyncConcreteApi

        client = AsyncConcreteApi()


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


        asyncio.run(main())
        """
        _response = await self._raw_client.start_vector_update(request_options=request_options)
        return _response.data


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