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

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.model_reasoning_options_response import ModelReasoningOptionsResponse
from ..types.models_list_response import ModelsListResponse


class RawModelsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def list_models(
        self,
        *,
        ui_models_only: typing.Optional[bool] = None,
        include_pricing: typing.Optional[bool] = None,
        include_details: typing.Optional[bool] = None,
        include_capabilities: typing.Optional[bool] = None,
        include_deprecated: typing.Optional[bool] = None,
        include_legacy: typing.Optional[bool] = None,
        include_recent_usage: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ModelsListResponse]:
        """
        List available AI models with their capabilities and configuration.

        Authentication:
            Requires either Bearer token or X-API-Key header

        Query Parameters:
            ui_models_only: Filter to show only UI-visible models (default: False)
            include_pricing: Include pricing information (default: False)
            include_details: Include detailed model information (default: False)
            include_capabilities: Include model capabilities array (default: True)
            include_deprecated: Include deprecated models (default: False)
            include_legacy: Include legacy models (default: False)
            include_recent_usage: Include last_used_at timestamp for API key (default: False)

        Returns:
            ModelsListResponse with list of models and total count

        Parameters
        ----------
        ui_models_only : typing.Optional[bool]

        include_pricing : typing.Optional[bool]

        include_details : typing.Optional[bool]

        include_capabilities : typing.Optional[bool]

        include_deprecated : typing.Optional[bool]

        include_legacy : typing.Optional[bool]

        include_recent_usage : typing.Optional[bool]

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

        Returns
        -------
        HttpResponse[ModelsListResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/models",
            method="GET",
            params={
                "ui_models_only": ui_models_only,
                "include_pricing": include_pricing,
                "include_details": include_details,
                "include_capabilities": include_capabilities,
                "include_deprecated": include_deprecated,
                "include_legacy": include_legacy,
                "include_recent_usage": include_recent_usage,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ModelsListResponse,
                    parse_obj_as(
                        type_=ModelsListResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get_reasoning_options(
        self, *, model_key: str, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[ModelReasoningOptionsResponse]:
        """
        Get available reasoning effort and summary options for a specific model.

        Different models support different reasoning effort levels. Use this endpoint
        to discover which options are available for a given model before configuring
        an assistant or sending a chat request.

        Authentication:
            Requires either Bearer token or X-API-Key header

        Query Parameters:
            model_key: The model key to look up (e.g., 'claude-sonnet-4', 'o3-mini')

        Returns:
            ModelReasoningOptionsResponse with available effort and summary options

        Parameters
        ----------
        model_key : str

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

        Returns
        -------
        HttpResponse[ModelReasoningOptionsResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/models/reasoning-options",
            method="GET",
            params={
                "model_key": model_key,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ModelReasoningOptionsResponse,
                    parse_obj_as(
                        type_=ModelReasoningOptionsResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


class AsyncRawModelsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list_models(
        self,
        *,
        ui_models_only: typing.Optional[bool] = None,
        include_pricing: typing.Optional[bool] = None,
        include_details: typing.Optional[bool] = None,
        include_capabilities: typing.Optional[bool] = None,
        include_deprecated: typing.Optional[bool] = None,
        include_legacy: typing.Optional[bool] = None,
        include_recent_usage: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ModelsListResponse]:
        """
        List available AI models with their capabilities and configuration.

        Authentication:
            Requires either Bearer token or X-API-Key header

        Query Parameters:
            ui_models_only: Filter to show only UI-visible models (default: False)
            include_pricing: Include pricing information (default: False)
            include_details: Include detailed model information (default: False)
            include_capabilities: Include model capabilities array (default: True)
            include_deprecated: Include deprecated models (default: False)
            include_legacy: Include legacy models (default: False)
            include_recent_usage: Include last_used_at timestamp for API key (default: False)

        Returns:
            ModelsListResponse with list of models and total count

        Parameters
        ----------
        ui_models_only : typing.Optional[bool]

        include_pricing : typing.Optional[bool]

        include_details : typing.Optional[bool]

        include_capabilities : typing.Optional[bool]

        include_deprecated : typing.Optional[bool]

        include_legacy : typing.Optional[bool]

        include_recent_usage : typing.Optional[bool]

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

        Returns
        -------
        AsyncHttpResponse[ModelsListResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/models",
            method="GET",
            params={
                "ui_models_only": ui_models_only,
                "include_pricing": include_pricing,
                "include_details": include_details,
                "include_capabilities": include_capabilities,
                "include_deprecated": include_deprecated,
                "include_legacy": include_legacy,
                "include_recent_usage": include_recent_usage,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ModelsListResponse,
                    parse_obj_as(
                        type_=ModelsListResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get_reasoning_options(
        self, *, model_key: str, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[ModelReasoningOptionsResponse]:
        """
        Get available reasoning effort and summary options for a specific model.

        Different models support different reasoning effort levels. Use this endpoint
        to discover which options are available for a given model before configuring
        an assistant or sending a chat request.

        Authentication:
            Requires either Bearer token or X-API-Key header

        Query Parameters:
            model_key: The model key to look up (e.g., 'claude-sonnet-4', 'o3-mini')

        Returns:
            ModelReasoningOptionsResponse with available effort and summary options

        Parameters
        ----------
        model_key : str

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

        Returns
        -------
        AsyncHttpResponse[ModelReasoningOptionsResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/models/reasoning-options",
            method="GET",
            params={
                "model_key": model_key,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ModelReasoningOptionsResponse,
                    parse_obj_as(
                        type_=ModelReasoningOptionsResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
