# 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 ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.assistant_active_session_response import AssistantActiveSessionResponse
from ..types.assistant_mbp_config_response import AssistantMbpConfigResponse
from ..types.regenerate_email_response import RegenerateEmailResponse
from ..types.session_response import SessionResponse

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


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

    def get_mbp_config(
        self, assistant_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[AssistantMbpConfigResponse]:
        """
        Get an assistant's Meeting Buddy Protocol configuration.

        Parameters
        ----------
        assistant_id : str

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

        Returns
        -------
        HttpResponse[AssistantMbpConfigResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/assistants/{jsonable_encoder(assistant_id)}/mbp-config",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AssistantMbpConfigResponse,
                    parse_obj_as(
                        type_=AssistantMbpConfigResponse,  # 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 upsert_mbp_config(
        self,
        assistant_id: str,
        *,
        join_mode: typing.Optional[str] = OMIT,
        is_enabled: typing.Optional[bool] = OMIT,
        bot_name_override: typing.Optional[str] = OMIT,
        trigger_patterns: typing.Optional[typing.Sequence[str]] = OMIT,
        respond_to_direct_messages: typing.Optional[bool] = OMIT,
        respond_to_group_mentions: typing.Optional[bool] = OMIT,
        auto_join_rule_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        allowed_tool_categories: typing.Optional[typing.Sequence[str]] = OMIT,
        max_response_time_seconds: typing.Optional[int] = OMIT,
        meeting_summary_enabled: typing.Optional[bool] = OMIT,
        transcription_enabled: typing.Optional[bool] = OMIT,
        follow_user_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AssistantMbpConfigResponse]:
        """
        Create or update an assistant's MBP configuration.

        Parameters
        ----------
        assistant_id : str

        join_mode : typing.Optional[str]
            Join mode: manual, calendar, or always

        is_enabled : typing.Optional[bool]
            Whether MBP is enabled

        bot_name_override : typing.Optional[str]
            Override bot display name (null = use assistant name)

        trigger_patterns : typing.Optional[typing.Sequence[str]]
            Chat trigger patterns, e.g. ['@{name}', 'Hey {name}']

        respond_to_direct_messages : typing.Optional[bool]
            Respond to direct messages in meeting chat

        respond_to_group_mentions : typing.Optional[bool]
            Respond when mentioned in group chat

        auto_join_rule_ids : typing.Optional[typing.Sequence[str]]
            Linked auto-join rule IDs

        allowed_tool_categories : typing.Optional[typing.Sequence[str]]
            Tool categories allowed during meetings

        max_response_time_seconds : typing.Optional[int]
            Max seconds before placeholder response

        meeting_summary_enabled : typing.Optional[bool]
            Auto-generate meeting summary

        transcription_enabled : typing.Optional[bool]
            Enable transcription during meetings

        follow_user_ids : typing.Optional[typing.Sequence[str]]
            User IDs whose meetings this assistant should auto-join

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

        Returns
        -------
        HttpResponse[AssistantMbpConfigResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/assistants/{jsonable_encoder(assistant_id)}/mbp-config",
            method="PUT",
            json={
                "join_mode": join_mode,
                "is_enabled": is_enabled,
                "bot_name_override": bot_name_override,
                "trigger_patterns": trigger_patterns,
                "respond_to_direct_messages": respond_to_direct_messages,
                "respond_to_group_mentions": respond_to_group_mentions,
                "auto_join_rule_ids": auto_join_rule_ids,
                "allowed_tool_categories": allowed_tool_categories,
                "max_response_time_seconds": max_response_time_seconds,
                "meeting_summary_enabled": meeting_summary_enabled,
                "transcription_enabled": transcription_enabled,
                "follow_user_ids": follow_user_ids,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AssistantMbpConfigResponse,
                    parse_obj_as(
                        type_=AssistantMbpConfigResponse,  # 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_mbp_config(
        self, assistant_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[None]:
        """
        Remove Meeting Buddy capability from an assistant.

        Parameters
        ----------
        assistant_id : str

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/assistants/{jsonable_encoder(assistant_id)}/mbp-config",
            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 assistant_join_meeting(
        self,
        assistant_id: str,
        *,
        meeting_link: str,
        transcription_language: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[SessionResponse]:
        """
        Create a Meeting Buddy session on behalf of an assistant. The bot joins the meeting using the assistant's name (or its configured override). Only one assistant can be in a meeting at a time within the same organization.

        Parameters
        ----------
        assistant_id : str

        meeting_link : str
            Meeting URL to join

        transcription_language : typing.Optional[str]
            Language code for transcription

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

        Returns
        -------
        HttpResponse[SessionResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/assistants/{jsonable_encoder(assistant_id)}/mbp/join",
            method="POST",
            json={
                "meeting_link": meeting_link,
                "transcription_language": transcription_language,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SessionResponse,
                    parse_obj_as(
                        type_=SessionResponse,  # 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 list_assistant_active_sessions(
        self, assistant_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[AssistantActiveSessionResponse]:
        """
        Returns all active Meeting Buddy sessions that were initiated by the specified assistant.

        Parameters
        ----------
        assistant_id : str

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

        Returns
        -------
        HttpResponse[AssistantActiveSessionResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/assistants/{jsonable_encoder(assistant_id)}/mbp/active-sessions",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AssistantActiveSessionResponse,
                    parse_obj_as(
                        type_=AssistantActiveSessionResponse,  # 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 regenerate_meeting_email(
        self, assistant_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[RegenerateEmailResponse]:
        """
        Force regenerate the meeting email address for an assistant.

        Parameters
        ----------
        assistant_id : str

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

        Returns
        -------
        HttpResponse[RegenerateEmailResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/assistants/{jsonable_encoder(assistant_id)}/meeting-email/regenerate",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    RegenerateEmailResponse,
                    parse_obj_as(
                        type_=RegenerateEmailResponse,  # 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 AsyncRawAssistantMbpConfigurationClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def get_mbp_config(
        self, assistant_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[AssistantMbpConfigResponse]:
        """
        Get an assistant's Meeting Buddy Protocol configuration.

        Parameters
        ----------
        assistant_id : str

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

        Returns
        -------
        AsyncHttpResponse[AssistantMbpConfigResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/assistants/{jsonable_encoder(assistant_id)}/mbp-config",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AssistantMbpConfigResponse,
                    parse_obj_as(
                        type_=AssistantMbpConfigResponse,  # 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 upsert_mbp_config(
        self,
        assistant_id: str,
        *,
        join_mode: typing.Optional[str] = OMIT,
        is_enabled: typing.Optional[bool] = OMIT,
        bot_name_override: typing.Optional[str] = OMIT,
        trigger_patterns: typing.Optional[typing.Sequence[str]] = OMIT,
        respond_to_direct_messages: typing.Optional[bool] = OMIT,
        respond_to_group_mentions: typing.Optional[bool] = OMIT,
        auto_join_rule_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        allowed_tool_categories: typing.Optional[typing.Sequence[str]] = OMIT,
        max_response_time_seconds: typing.Optional[int] = OMIT,
        meeting_summary_enabled: typing.Optional[bool] = OMIT,
        transcription_enabled: typing.Optional[bool] = OMIT,
        follow_user_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AssistantMbpConfigResponse]:
        """
        Create or update an assistant's MBP configuration.

        Parameters
        ----------
        assistant_id : str

        join_mode : typing.Optional[str]
            Join mode: manual, calendar, or always

        is_enabled : typing.Optional[bool]
            Whether MBP is enabled

        bot_name_override : typing.Optional[str]
            Override bot display name (null = use assistant name)

        trigger_patterns : typing.Optional[typing.Sequence[str]]
            Chat trigger patterns, e.g. ['@{name}', 'Hey {name}']

        respond_to_direct_messages : typing.Optional[bool]
            Respond to direct messages in meeting chat

        respond_to_group_mentions : typing.Optional[bool]
            Respond when mentioned in group chat

        auto_join_rule_ids : typing.Optional[typing.Sequence[str]]
            Linked auto-join rule IDs

        allowed_tool_categories : typing.Optional[typing.Sequence[str]]
            Tool categories allowed during meetings

        max_response_time_seconds : typing.Optional[int]
            Max seconds before placeholder response

        meeting_summary_enabled : typing.Optional[bool]
            Auto-generate meeting summary

        transcription_enabled : typing.Optional[bool]
            Enable transcription during meetings

        follow_user_ids : typing.Optional[typing.Sequence[str]]
            User IDs whose meetings this assistant should auto-join

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

        Returns
        -------
        AsyncHttpResponse[AssistantMbpConfigResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/assistants/{jsonable_encoder(assistant_id)}/mbp-config",
            method="PUT",
            json={
                "join_mode": join_mode,
                "is_enabled": is_enabled,
                "bot_name_override": bot_name_override,
                "trigger_patterns": trigger_patterns,
                "respond_to_direct_messages": respond_to_direct_messages,
                "respond_to_group_mentions": respond_to_group_mentions,
                "auto_join_rule_ids": auto_join_rule_ids,
                "allowed_tool_categories": allowed_tool_categories,
                "max_response_time_seconds": max_response_time_seconds,
                "meeting_summary_enabled": meeting_summary_enabled,
                "transcription_enabled": transcription_enabled,
                "follow_user_ids": follow_user_ids,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AssistantMbpConfigResponse,
                    parse_obj_as(
                        type_=AssistantMbpConfigResponse,  # 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_mbp_config(
        self, assistant_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[None]:
        """
        Remove Meeting Buddy capability from an assistant.

        Parameters
        ----------
        assistant_id : str

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/assistants/{jsonable_encoder(assistant_id)}/mbp-config",
            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 assistant_join_meeting(
        self,
        assistant_id: str,
        *,
        meeting_link: str,
        transcription_language: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[SessionResponse]:
        """
        Create a Meeting Buddy session on behalf of an assistant. The bot joins the meeting using the assistant's name (or its configured override). Only one assistant can be in a meeting at a time within the same organization.

        Parameters
        ----------
        assistant_id : str

        meeting_link : str
            Meeting URL to join

        transcription_language : typing.Optional[str]
            Language code for transcription

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

        Returns
        -------
        AsyncHttpResponse[SessionResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/assistants/{jsonable_encoder(assistant_id)}/mbp/join",
            method="POST",
            json={
                "meeting_link": meeting_link,
                "transcription_language": transcription_language,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SessionResponse,
                    parse_obj_as(
                        type_=SessionResponse,  # 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 list_assistant_active_sessions(
        self, assistant_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[AssistantActiveSessionResponse]:
        """
        Returns all active Meeting Buddy sessions that were initiated by the specified assistant.

        Parameters
        ----------
        assistant_id : str

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

        Returns
        -------
        AsyncHttpResponse[AssistantActiveSessionResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/assistants/{jsonable_encoder(assistant_id)}/mbp/active-sessions",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AssistantActiveSessionResponse,
                    parse_obj_as(
                        type_=AssistantActiveSessionResponse,  # 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 regenerate_meeting_email(
        self, assistant_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[RegenerateEmailResponse]:
        """
        Force regenerate the meeting email address for an assistant.

        Parameters
        ----------
        assistant_id : str

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

        Returns
        -------
        AsyncHttpResponse[RegenerateEmailResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/assistants/{jsonable_encoder(assistant_id)}/meeting-email/regenerate",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    RegenerateEmailResponse,
                    parse_obj_as(
                        type_=RegenerateEmailResponse,  # 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)
