# 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.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.intelligence_config_list_response import IntelligenceConfigListResponse
from ..types.intelligence_config_response import IntelligenceConfigResponse
from ..types.prompt_module import PromptModule

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


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

    def list_intelligence_configs(
        self, *, scope: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[IntelligenceConfigListResponse]:
        """
        List intelligence configs. Use scope=org for org-level only, scope=user for user-level only.

        Parameters
        ----------
        scope : typing.Optional[str]

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

        Returns
        -------
        HttpResponse[IntelligenceConfigListResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/meeting-buddy/intelligence-configs",
            method="GET",
            params={
                "scope": scope,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    IntelligenceConfigListResponse,
                    parse_obj_as(
                        type_=IntelligenceConfigListResponse,  # 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 create_intelligence_config(
        self,
        *,
        name: str,
        is_default: typing.Optional[bool] = OMIT,
        prompts: typing.Optional[typing.Sequence[PromptModule]] = OMIT,
        model_override: typing.Optional[str] = OMIT,
        output_sections: typing.Optional[typing.Sequence[str]] = OMIT,
        meeting_type_filter: typing.Optional[typing.Sequence[str]] = OMIT,
        auto_vector_store_id: typing.Optional[str] = OMIT,
        user_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[IntelligenceConfigResponse]:
        """
        Create an intelligence config. Omit user_id for org-level config.

        Parameters
        ----------
        name : str

        is_default : typing.Optional[bool]

        prompts : typing.Optional[typing.Sequence[PromptModule]]

        model_override : typing.Optional[str]

        output_sections : typing.Optional[typing.Sequence[str]]

        meeting_type_filter : typing.Optional[typing.Sequence[str]]

        auto_vector_store_id : typing.Optional[str]

        user_id : typing.Optional[str]
            Set to create a user-level config. Omit for org-level.

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

        Returns
        -------
        HttpResponse[IntelligenceConfigResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/meeting-buddy/intelligence-configs",
            method="POST",
            json={
                "name": name,
                "is_default": is_default,
                "prompts": convert_and_respect_annotation_metadata(
                    object_=prompts, annotation=typing.Sequence[PromptModule], direction="write"
                ),
                "model_override": model_override,
                "output_sections": output_sections,
                "meeting_type_filter": meeting_type_filter,
                "auto_vector_store_id": auto_vector_store_id,
                "user_id": user_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    IntelligenceConfigResponse,
                    parse_obj_as(
                        type_=IntelligenceConfigResponse,  # 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 delete_intelligence_config(
        self, config_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[None]:
        """
        Soft-delete an intelligence config by ID.

        Parameters
        ----------
        config_id : str

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/meeting-buddy/intelligence-configs/{jsonable_encoder(config_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return HttpResponse(response=_response, data=None)
            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 update_intelligence_config(
        self,
        config_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        is_default: typing.Optional[bool] = OMIT,
        prompts: typing.Optional[typing.Sequence[PromptModule]] = OMIT,
        model_override: typing.Optional[str] = OMIT,
        output_sections: typing.Optional[typing.Sequence[str]] = OMIT,
        meeting_type_filter: typing.Optional[typing.Sequence[str]] = OMIT,
        auto_vector_store_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[IntelligenceConfigResponse]:
        """
        Update an intelligence config by ID.

        Parameters
        ----------
        config_id : str

        name : typing.Optional[str]

        is_default : typing.Optional[bool]

        prompts : typing.Optional[typing.Sequence[PromptModule]]

        model_override : typing.Optional[str]

        output_sections : typing.Optional[typing.Sequence[str]]

        meeting_type_filter : typing.Optional[typing.Sequence[str]]

        auto_vector_store_id : typing.Optional[str]

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

        Returns
        -------
        HttpResponse[IntelligenceConfigResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/meeting-buddy/intelligence-configs/{jsonable_encoder(config_id)}",
            method="PATCH",
            json={
                "name": name,
                "is_default": is_default,
                "prompts": convert_and_respect_annotation_metadata(
                    object_=prompts, annotation=typing.Optional[typing.Sequence[PromptModule]], direction="write"
                ),
                "model_override": model_override,
                "output_sections": output_sections,
                "meeting_type_filter": meeting_type_filter,
                "auto_vector_store_id": auto_vector_store_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    IntelligenceConfigResponse,
                    parse_obj_as(
                        type_=IntelligenceConfigResponse,  # 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 AsyncRawMeetingBuddyIntelligenceConfigClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list_intelligence_configs(
        self, *, scope: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[IntelligenceConfigListResponse]:
        """
        List intelligence configs. Use scope=org for org-level only, scope=user for user-level only.

        Parameters
        ----------
        scope : typing.Optional[str]

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

        Returns
        -------
        AsyncHttpResponse[IntelligenceConfigListResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/meeting-buddy/intelligence-configs",
            method="GET",
            params={
                "scope": scope,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    IntelligenceConfigListResponse,
                    parse_obj_as(
                        type_=IntelligenceConfigListResponse,  # 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 create_intelligence_config(
        self,
        *,
        name: str,
        is_default: typing.Optional[bool] = OMIT,
        prompts: typing.Optional[typing.Sequence[PromptModule]] = OMIT,
        model_override: typing.Optional[str] = OMIT,
        output_sections: typing.Optional[typing.Sequence[str]] = OMIT,
        meeting_type_filter: typing.Optional[typing.Sequence[str]] = OMIT,
        auto_vector_store_id: typing.Optional[str] = OMIT,
        user_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[IntelligenceConfigResponse]:
        """
        Create an intelligence config. Omit user_id for org-level config.

        Parameters
        ----------
        name : str

        is_default : typing.Optional[bool]

        prompts : typing.Optional[typing.Sequence[PromptModule]]

        model_override : typing.Optional[str]

        output_sections : typing.Optional[typing.Sequence[str]]

        meeting_type_filter : typing.Optional[typing.Sequence[str]]

        auto_vector_store_id : typing.Optional[str]

        user_id : typing.Optional[str]
            Set to create a user-level config. Omit for org-level.

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

        Returns
        -------
        AsyncHttpResponse[IntelligenceConfigResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/meeting-buddy/intelligence-configs",
            method="POST",
            json={
                "name": name,
                "is_default": is_default,
                "prompts": convert_and_respect_annotation_metadata(
                    object_=prompts, annotation=typing.Sequence[PromptModule], direction="write"
                ),
                "model_override": model_override,
                "output_sections": output_sections,
                "meeting_type_filter": meeting_type_filter,
                "auto_vector_store_id": auto_vector_store_id,
                "user_id": user_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    IntelligenceConfigResponse,
                    parse_obj_as(
                        type_=IntelligenceConfigResponse,  # 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 delete_intelligence_config(
        self, config_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[None]:
        """
        Soft-delete an intelligence config by ID.

        Parameters
        ----------
        config_id : str

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/meeting-buddy/intelligence-configs/{jsonable_encoder(config_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return AsyncHttpResponse(response=_response, data=None)
            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 update_intelligence_config(
        self,
        config_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        is_default: typing.Optional[bool] = OMIT,
        prompts: typing.Optional[typing.Sequence[PromptModule]] = OMIT,
        model_override: typing.Optional[str] = OMIT,
        output_sections: typing.Optional[typing.Sequence[str]] = OMIT,
        meeting_type_filter: typing.Optional[typing.Sequence[str]] = OMIT,
        auto_vector_store_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[IntelligenceConfigResponse]:
        """
        Update an intelligence config by ID.

        Parameters
        ----------
        config_id : str

        name : typing.Optional[str]

        is_default : typing.Optional[bool]

        prompts : typing.Optional[typing.Sequence[PromptModule]]

        model_override : typing.Optional[str]

        output_sections : typing.Optional[typing.Sequence[str]]

        meeting_type_filter : typing.Optional[typing.Sequence[str]]

        auto_vector_store_id : typing.Optional[str]

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

        Returns
        -------
        AsyncHttpResponse[IntelligenceConfigResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/meeting-buddy/intelligence-configs/{jsonable_encoder(config_id)}",
            method="PATCH",
            json={
                "name": name,
                "is_default": is_default,
                "prompts": convert_and_respect_annotation_metadata(
                    object_=prompts, annotation=typing.Optional[typing.Sequence[PromptModule]], direction="write"
                ),
                "model_override": model_override,
                "output_sections": output_sections,
                "meeting_type_filter": meeting_type_filter,
                "auto_vector_store_id": auto_vector_store_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    IntelligenceConfigResponse,
                    parse_obj_as(
                        type_=IntelligenceConfigResponse,  # 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)
