# 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.org_settings_response import OrgSettingsResponse

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


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

    def get_org_settings(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[OrgSettingsResponse]:
        """
        Get organization-level Meeting Buddy settings.

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

        Returns
        -------
        HttpResponse[OrgSettingsResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/meeting-buddy/settings",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OrgSettingsResponse,
                    parse_obj_as(
                        type_=OrgSettingsResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _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_org_settings(
        self,
        *,
        auto_share_link_in_chat: typing.Optional[bool] = OMIT,
        public_chat_enabled: typing.Optional[bool] = OMIT,
        public_chat_message_limit: typing.Optional[int] = OMIT,
        public_chat_model: typing.Optional[str] = OMIT,
        share_link_expiry_days: typing.Optional[int] = OMIT,
        chat_agent_enabled: typing.Optional[bool] = OMIT,
        chat_agent_name: typing.Optional[str] = OMIT,
        greeting_enabled: typing.Optional[bool] = OMIT,
        greeting_message: typing.Optional[str] = OMIT,
        farewell_enabled: typing.Optional[bool] = OMIT,
        farewell_include_summary: typing.Optional[bool] = OMIT,
        email_enabled: typing.Optional[bool] = OMIT,
        email_recipients: typing.Optional[str] = OMIT,
        email_custom_recipients: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[OrgSettingsResponse]:
        """
        Update organization-level Meeting Buddy settings.

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

        public_chat_enabled : typing.Optional[bool]

        public_chat_message_limit : typing.Optional[int]

        public_chat_model : typing.Optional[str]

        share_link_expiry_days : typing.Optional[int]

        chat_agent_enabled : typing.Optional[bool]

        chat_agent_name : typing.Optional[str]

        greeting_enabled : typing.Optional[bool]

        greeting_message : typing.Optional[str]

        farewell_enabled : typing.Optional[bool]

        farewell_include_summary : typing.Optional[bool]

        email_enabled : typing.Optional[bool]

        email_recipients : typing.Optional[str]

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

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

        Returns
        -------
        HttpResponse[OrgSettingsResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/meeting-buddy/settings",
            method="PATCH",
            json={
                "auto_share_link_in_chat": auto_share_link_in_chat,
                "public_chat_enabled": public_chat_enabled,
                "public_chat_message_limit": public_chat_message_limit,
                "public_chat_model": public_chat_model,
                "share_link_expiry_days": share_link_expiry_days,
                "chat_agent_enabled": chat_agent_enabled,
                "chat_agent_name": chat_agent_name,
                "greeting_enabled": greeting_enabled,
                "greeting_message": greeting_message,
                "farewell_enabled": farewell_enabled,
                "farewell_include_summary": farewell_include_summary,
                "email_enabled": email_enabled,
                "email_recipients": email_recipients,
                "email_custom_recipients": email_custom_recipients,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OrgSettingsResponse,
                    parse_obj_as(
                        type_=OrgSettingsResponse,  # 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 AsyncRawMeetingBuddySettingsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def get_org_settings(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[OrgSettingsResponse]:
        """
        Get organization-level Meeting Buddy settings.

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

        Returns
        -------
        AsyncHttpResponse[OrgSettingsResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/meeting-buddy/settings",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OrgSettingsResponse,
                    parse_obj_as(
                        type_=OrgSettingsResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _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_org_settings(
        self,
        *,
        auto_share_link_in_chat: typing.Optional[bool] = OMIT,
        public_chat_enabled: typing.Optional[bool] = OMIT,
        public_chat_message_limit: typing.Optional[int] = OMIT,
        public_chat_model: typing.Optional[str] = OMIT,
        share_link_expiry_days: typing.Optional[int] = OMIT,
        chat_agent_enabled: typing.Optional[bool] = OMIT,
        chat_agent_name: typing.Optional[str] = OMIT,
        greeting_enabled: typing.Optional[bool] = OMIT,
        greeting_message: typing.Optional[str] = OMIT,
        farewell_enabled: typing.Optional[bool] = OMIT,
        farewell_include_summary: typing.Optional[bool] = OMIT,
        email_enabled: typing.Optional[bool] = OMIT,
        email_recipients: typing.Optional[str] = OMIT,
        email_custom_recipients: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[OrgSettingsResponse]:
        """
        Update organization-level Meeting Buddy settings.

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

        public_chat_enabled : typing.Optional[bool]

        public_chat_message_limit : typing.Optional[int]

        public_chat_model : typing.Optional[str]

        share_link_expiry_days : typing.Optional[int]

        chat_agent_enabled : typing.Optional[bool]

        chat_agent_name : typing.Optional[str]

        greeting_enabled : typing.Optional[bool]

        greeting_message : typing.Optional[str]

        farewell_enabled : typing.Optional[bool]

        farewell_include_summary : typing.Optional[bool]

        email_enabled : typing.Optional[bool]

        email_recipients : typing.Optional[str]

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

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

        Returns
        -------
        AsyncHttpResponse[OrgSettingsResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/meeting-buddy/settings",
            method="PATCH",
            json={
                "auto_share_link_in_chat": auto_share_link_in_chat,
                "public_chat_enabled": public_chat_enabled,
                "public_chat_message_limit": public_chat_message_limit,
                "public_chat_model": public_chat_model,
                "share_link_expiry_days": share_link_expiry_days,
                "chat_agent_enabled": chat_agent_enabled,
                "chat_agent_name": chat_agent_name,
                "greeting_enabled": greeting_enabled,
                "greeting_message": greeting_message,
                "farewell_enabled": farewell_enabled,
                "farewell_include_summary": farewell_include_summary,
                "email_enabled": email_enabled,
                "email_recipients": email_recipients,
                "email_custom_recipients": email_custom_recipients,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OrgSettingsResponse,
                    parse_obj_as(
                        type_=OrgSettingsResponse,  # 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)
