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

import typing
from json.decoder import JSONDecodeError

from ...commons.errors.access_denied_error import (
    AccessDeniedError as commons_errors_access_denied_error_AccessDeniedError,
)
from ...commons.errors.error import Error
from ...commons.errors.method_not_allowed_error import (
    MethodNotAllowedError as commons_errors_method_not_allowed_error_MethodNotAllowedError,
)
from ...commons.errors.not_found_error import (
    NotFoundError as commons_errors_not_found_error_NotFoundError,
)
from ...commons.errors.unauthorized_error import (
    UnauthorizedError as commons_errors_unauthorized_error_UnauthorizedError,
)
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 ..dashboard_widgets.types.dashboard_widget_filter import DashboardWidgetFilter
from ..errors.errors.access_denied_error import (
    AccessDeniedError as unstable_errors_errors_access_denied_error_AccessDeniedError,
)
from ..errors.errors.bad_request_error import BadRequestError
from ..errors.errors.conflict_error import ConflictError
from ..errors.errors.internal_server_error import InternalServerError
from ..errors.errors.method_not_allowed_error import (
    MethodNotAllowedError as unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError,
)
from ..errors.errors.not_found_error import (
    NotFoundError as unstable_errors_errors_not_found_error_NotFoundError,
)
from ..errors.errors.too_many_requests_error import TooManyRequestsError
from ..errors.errors.unauthorized_error import (
    UnauthorizedError as unstable_errors_errors_unauthorized_error_UnauthorizedError,
)
from ..errors.types.public_api_error import PublicApiError
from .types.create_dashboard_placement_request import CreateDashboardPlacementRequest
from .types.dashboard import Dashboard
from .types.dashboard_definition import DashboardDefinition
from .types.dashboard_list import DashboardList
from .types.dashboard_placement import DashboardPlacement
from .types.delete_dashboard_placement_response import DeleteDashboardPlacementResponse
from .types.delete_dashboard_response import DeleteDashboardResponse

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


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

    def list(
        self,
        *,
        page: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[DashboardList]:
        """
        List dashboards in the project, ordered by most recently updated
        first.

        Parameters
        ----------
        page : typing.Optional[int]
            1-based page number. Defaults to `1`.

        limit : typing.Optional[int]
            Maximum number of items per page. Defaults to `50`.

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

        Returns
        -------
        HttpResponse[DashboardList]
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/public/unstable/dashboards",
            method="GET",
            params={
                "page": page,
                "limit": limit,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DashboardList,
                    parse_obj_as(
                        type_=DashboardList,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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(
        self,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        definition: typing.Optional[DashboardDefinition] = OMIT,
        filters: typing.Optional[typing.Sequence[DashboardWidgetFilter]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[Dashboard]:
        """
        Create a dashboard.

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

        description : typing.Optional[str]

        definition : typing.Optional[DashboardDefinition]

        filters : typing.Optional[typing.Sequence[DashboardWidgetFilter]]

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

        Returns
        -------
        HttpResponse[Dashboard]
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/public/unstable/dashboards",
            method="POST",
            json={
                "name": name,
                "description": description,
                "definition": convert_and_respect_annotation_metadata(
                    object_=definition,
                    annotation=DashboardDefinition,
                    direction="write",
                ),
                "filters": convert_and_respect_annotation_metadata(
                    object_=filters,
                    annotation=typing.Sequence[DashboardWidgetFilter],
                    direction="write",
                ),
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Dashboard,
                    parse_obj_as(
                        type_=Dashboard,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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(
        self,
        dashboard_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[Dashboard]:
        """
        Get a dashboard by id.

        Parameters
        ----------
        dashboard_id : str

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

        Returns
        -------
        HttpResponse[Dashboard]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/public/unstable/dashboards/{jsonable_encoder(dashboard_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Dashboard,
                    parse_obj_as(
                        type_=Dashboard,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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(
        self,
        dashboard_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        definition: typing.Optional[DashboardDefinition] = OMIT,
        filters: typing.Optional[typing.Sequence[DashboardWidgetFilter]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[Dashboard]:
        """
        Update a dashboard's name, description, definition, or filters.

        Parameters
        ----------
        dashboard_id : str

        name : typing.Optional[str]

        description : typing.Optional[str]

        definition : typing.Optional[DashboardDefinition]

        filters : typing.Optional[typing.Sequence[DashboardWidgetFilter]]

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

        Returns
        -------
        HttpResponse[Dashboard]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/public/unstable/dashboards/{jsonable_encoder(dashboard_id)}",
            method="PATCH",
            json={
                "name": name,
                "description": description,
                "definition": convert_and_respect_annotation_metadata(
                    object_=definition,
                    annotation=DashboardDefinition,
                    direction="write",
                ),
                "filters": convert_and_respect_annotation_metadata(
                    object_=filters,
                    annotation=typing.Sequence[DashboardWidgetFilter],
                    direction="write",
                ),
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Dashboard,
                    parse_obj_as(
                        type_=Dashboard,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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(
        self,
        dashboard_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[DeleteDashboardResponse]:
        """
        Delete a dashboard.

        Parameters
        ----------
        dashboard_id : str

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

        Returns
        -------
        HttpResponse[DeleteDashboardResponse]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/public/unstable/dashboards/{jsonable_encoder(dashboard_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DeleteDashboardResponse,
                    parse_obj_as(
                        type_=DeleteDashboardResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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 add_placement(
        self,
        dashboard_id: str,
        *,
        request: CreateDashboardPlacementRequest,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[DashboardPlacement]:
        """
        Add a placement to a dashboard grid (see `DashboardPlacement` for
        grid semantics).

        `id` and the position fields are optional: when omitted, the
        placement gets a server-generated id and is appended below all
        existing tiles as a 6x6 tile. Returns the created placement.

        The referenced widget must exist in the same project or be a
        Langfuse-managed widget. The API returns `409` if a placement with
        the same `id` already exists on the dashboard.

        Parameters
        ----------
        dashboard_id : str

        request : CreateDashboardPlacementRequest

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

        Returns
        -------
        HttpResponse[DashboardPlacement]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/public/unstable/dashboards/{jsonable_encoder(dashboard_id)}/placements",
            method="POST",
            json=convert_and_respect_annotation_metadata(
                object_=request,
                annotation=CreateDashboardPlacementRequest,
                direction="write",
            ),
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DashboardPlacement,
                    parse_obj_as(
                        type_=DashboardPlacement,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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_placement(
        self,
        dashboard_id: str,
        placement_id: str,
        *,
        x: typing.Optional[int] = OMIT,
        y: typing.Optional[int] = OMIT,
        width: typing.Optional[int] = OMIT,
        height: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[DashboardPlacement]:
        """
        Move or resize a placement. All fields are optional; at least one is
        required. Omitted fields keep their current value. The placement's
        content (widget/preset reference) and id cannot change — delete and
        re-add the placement to swap content. Returns the updated placement.

        Parameters
        ----------
        dashboard_id : str

        placement_id : str

        x : typing.Optional[int]
            Grid column (12-column grid).

        y : typing.Optional[int]
            Grid row.

        width : typing.Optional[int]
            Width in grid columns.

        height : typing.Optional[int]
            Height in grid rows.

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

        Returns
        -------
        HttpResponse[DashboardPlacement]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/public/unstable/dashboards/{jsonable_encoder(dashboard_id)}/placements/{jsonable_encoder(placement_id)}",
            method="PATCH",
            json={
                "x": x,
                "y": y,
                "width": width,
                "height": height,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DashboardPlacement,
                    parse_obj_as(
                        type_=DashboardPlacement,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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_placement(
        self,
        dashboard_id: str,
        placement_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[DeleteDashboardPlacementResponse]:
        """
        Remove a placement from a dashboard grid without deleting the referenced widget.

        Parameters
        ----------
        dashboard_id : str

        placement_id : str

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

        Returns
        -------
        HttpResponse[DeleteDashboardPlacementResponse]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/public/unstable/dashboards/{jsonable_encoder(dashboard_id)}/placements/{jsonable_encoder(placement_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DeleteDashboardPlacementResponse,
                    parse_obj_as(
                        type_=DeleteDashboardPlacementResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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 AsyncRawDashboardsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list(
        self,
        *,
        page: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[DashboardList]:
        """
        List dashboards in the project, ordered by most recently updated
        first.

        Parameters
        ----------
        page : typing.Optional[int]
            1-based page number. Defaults to `1`.

        limit : typing.Optional[int]
            Maximum number of items per page. Defaults to `50`.

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

        Returns
        -------
        AsyncHttpResponse[DashboardList]
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/public/unstable/dashboards",
            method="GET",
            params={
                "page": page,
                "limit": limit,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DashboardList,
                    parse_obj_as(
                        type_=DashboardList,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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(
        self,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        definition: typing.Optional[DashboardDefinition] = OMIT,
        filters: typing.Optional[typing.Sequence[DashboardWidgetFilter]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[Dashboard]:
        """
        Create a dashboard.

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

        description : typing.Optional[str]

        definition : typing.Optional[DashboardDefinition]

        filters : typing.Optional[typing.Sequence[DashboardWidgetFilter]]

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

        Returns
        -------
        AsyncHttpResponse[Dashboard]
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/public/unstable/dashboards",
            method="POST",
            json={
                "name": name,
                "description": description,
                "definition": convert_and_respect_annotation_metadata(
                    object_=definition,
                    annotation=DashboardDefinition,
                    direction="write",
                ),
                "filters": convert_and_respect_annotation_metadata(
                    object_=filters,
                    annotation=typing.Sequence[DashboardWidgetFilter],
                    direction="write",
                ),
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Dashboard,
                    parse_obj_as(
                        type_=Dashboard,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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(
        self,
        dashboard_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[Dashboard]:
        """
        Get a dashboard by id.

        Parameters
        ----------
        dashboard_id : str

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

        Returns
        -------
        AsyncHttpResponse[Dashboard]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/public/unstable/dashboards/{jsonable_encoder(dashboard_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Dashboard,
                    parse_obj_as(
                        type_=Dashboard,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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(
        self,
        dashboard_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        definition: typing.Optional[DashboardDefinition] = OMIT,
        filters: typing.Optional[typing.Sequence[DashboardWidgetFilter]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[Dashboard]:
        """
        Update a dashboard's name, description, definition, or filters.

        Parameters
        ----------
        dashboard_id : str

        name : typing.Optional[str]

        description : typing.Optional[str]

        definition : typing.Optional[DashboardDefinition]

        filters : typing.Optional[typing.Sequence[DashboardWidgetFilter]]

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

        Returns
        -------
        AsyncHttpResponse[Dashboard]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/public/unstable/dashboards/{jsonable_encoder(dashboard_id)}",
            method="PATCH",
            json={
                "name": name,
                "description": description,
                "definition": convert_and_respect_annotation_metadata(
                    object_=definition,
                    annotation=DashboardDefinition,
                    direction="write",
                ),
                "filters": convert_and_respect_annotation_metadata(
                    object_=filters,
                    annotation=typing.Sequence[DashboardWidgetFilter],
                    direction="write",
                ),
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Dashboard,
                    parse_obj_as(
                        type_=Dashboard,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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(
        self,
        dashboard_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[DeleteDashboardResponse]:
        """
        Delete a dashboard.

        Parameters
        ----------
        dashboard_id : str

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

        Returns
        -------
        AsyncHttpResponse[DeleteDashboardResponse]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/public/unstable/dashboards/{jsonable_encoder(dashboard_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DeleteDashboardResponse,
                    parse_obj_as(
                        type_=DeleteDashboardResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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 add_placement(
        self,
        dashboard_id: str,
        *,
        request: CreateDashboardPlacementRequest,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[DashboardPlacement]:
        """
        Add a placement to a dashboard grid (see `DashboardPlacement` for
        grid semantics).

        `id` and the position fields are optional: when omitted, the
        placement gets a server-generated id and is appended below all
        existing tiles as a 6x6 tile. Returns the created placement.

        The referenced widget must exist in the same project or be a
        Langfuse-managed widget. The API returns `409` if a placement with
        the same `id` already exists on the dashboard.

        Parameters
        ----------
        dashboard_id : str

        request : CreateDashboardPlacementRequest

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

        Returns
        -------
        AsyncHttpResponse[DashboardPlacement]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/public/unstable/dashboards/{jsonable_encoder(dashboard_id)}/placements",
            method="POST",
            json=convert_and_respect_annotation_metadata(
                object_=request,
                annotation=CreateDashboardPlacementRequest,
                direction="write",
            ),
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DashboardPlacement,
                    parse_obj_as(
                        type_=DashboardPlacement,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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_placement(
        self,
        dashboard_id: str,
        placement_id: str,
        *,
        x: typing.Optional[int] = OMIT,
        y: typing.Optional[int] = OMIT,
        width: typing.Optional[int] = OMIT,
        height: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[DashboardPlacement]:
        """
        Move or resize a placement. All fields are optional; at least one is
        required. Omitted fields keep their current value. The placement's
        content (widget/preset reference) and id cannot change — delete and
        re-add the placement to swap content. Returns the updated placement.

        Parameters
        ----------
        dashboard_id : str

        placement_id : str

        x : typing.Optional[int]
            Grid column (12-column grid).

        y : typing.Optional[int]
            Grid row.

        width : typing.Optional[int]
            Width in grid columns.

        height : typing.Optional[int]
            Height in grid rows.

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

        Returns
        -------
        AsyncHttpResponse[DashboardPlacement]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/public/unstable/dashboards/{jsonable_encoder(dashboard_id)}/placements/{jsonable_encoder(placement_id)}",
            method="PATCH",
            json={
                "x": x,
                "y": y,
                "width": width,
                "height": height,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DashboardPlacement,
                    parse_obj_as(
                        type_=DashboardPlacement,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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_placement(
        self,
        dashboard_id: str,
        placement_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[DeleteDashboardPlacementResponse]:
        """
        Remove a placement from a dashboard grid without deleting the referenced widget.

        Parameters
        ----------
        dashboard_id : str

        placement_id : str

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

        Returns
        -------
        AsyncHttpResponse[DeleteDashboardPlacementResponse]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/public/unstable/dashboards/{jsonable_encoder(dashboard_id)}/placements/{jsonable_encoder(placement_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DeleteDashboardPlacementResponse,
                    parse_obj_as(
                        type_=DeleteDashboardPlacementResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise unstable_errors_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise unstable_errors_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise unstable_errors_errors_not_found_error_NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PublicApiError,
                        parse_obj_as(
                            type_=PublicApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 400:
                raise Error(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise commons_errors_unauthorized_error_UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise commons_errors_access_denied_error_AccessDeniedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 405:
                raise commons_errors_method_not_allowed_error_MethodNotAllowedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise commons_errors_not_found_error_NotFoundError(
                    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,
        )
