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

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..errors.bad_request_error import BadRequestError
from ..errors.conflict_error import ConflictError
from ..errors.not_found_error import NotFoundError
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.alert_page_public import AlertPagePublic
from ..types.alert_public import AlertPublic
from ..types.alert_trigger_write import AlertTriggerWrite
from ..types.alert_write_alert_type import AlertWriteAlertType
from ..types.webhook_examples import WebhookExamples
from ..types.webhook_test_result import WebhookTestResult
from ..types.webhook_write import WebhookWrite
from .types.get_webhook_examples_request_alert_type import GetWebhookExamplesRequestAlertType

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


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

    def find_alerts(
        self,
        *,
        page: typing.Optional[int] = None,
        size: typing.Optional[int] = None,
        sorting: typing.Optional[str] = None,
        filters: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AlertPagePublic]:
        """
        Find alerts

        Parameters
        ----------
        page : typing.Optional[int]

        size : typing.Optional[int]

        sorting : typing.Optional[str]

        filters : typing.Optional[str]

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

        Returns
        -------
        HttpResponse[AlertPagePublic]
            OK
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/private/alerts",
            method="GET",
            params={
                "page": page,
                "size": size,
                "sorting": sorting,
                "filters": filters,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AlertPagePublic,
                    parse_obj_as(
                        type_=AlertPagePublic,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def create_alert(
        self,
        *,
        webhook: WebhookWrite,
        id: typing.Optional[str] = OMIT,
        name: typing.Optional[str] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        alert_type: typing.Optional[AlertWriteAlertType] = OMIT,
        metadata: typing.Optional[typing.Dict[str, str]] = OMIT,
        triggers: typing.Optional[typing.Sequence[AlertTriggerWrite]] = OMIT,
        project_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[None]:
        """
        Create alert

        Parameters
        ----------
        webhook : WebhookWrite

        id : typing.Optional[str]

        name : typing.Optional[str]

        enabled : typing.Optional[bool]

        alert_type : typing.Optional[AlertWriteAlertType]

        metadata : typing.Optional[typing.Dict[str, str]]

        triggers : typing.Optional[typing.Sequence[AlertTriggerWrite]]

        project_id : typing.Optional[str]
            Optional project scope for this alert. When set, the alert is scoped to the specified project. Do NOT also provide a 'scope:project' trigger config — the system will create it automatically from this field. Sending both project_id and a scope:project trigger config will result in an error.

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/private/alerts",
            method="POST",
            json={
                "id": id,
                "name": name,
                "enabled": enabled,
                "alert_type": alert_type,
                "metadata": metadata,
                "webhook": convert_and_respect_annotation_metadata(
                    object_=webhook, annotation=WebhookWrite, direction="write"
                ),
                "triggers": convert_and_respect_annotation_metadata(
                    object_=triggers, annotation=typing.Sequence[AlertTriggerWrite], direction="write"
                ),
                "project_id": project_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return HttpResponse(response=_response, data=None)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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_alert_batch(
        self, *, ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[None]:
        """
        Delete multiple alerts by their IDs

        Parameters
        ----------
        ids : typing.Sequence[str]

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/private/alerts/delete",
            method="POST",
            json={
                "ids": ids,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return HttpResponse(response=_response, data=None)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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_alert_by_id(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[AlertPublic]:
        """
        Get Alert by id

        Parameters
        ----------
        id : str

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

        Returns
        -------
        HttpResponse[AlertPublic]
            Alert resource
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/private/alerts/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AlertPublic,
                    parse_obj_as(
                        type_=AlertPublic,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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_alert(
        self,
        id_: str,
        *,
        webhook: WebhookWrite,
        id: typing.Optional[str] = OMIT,
        name: typing.Optional[str] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        alert_type: typing.Optional[AlertWriteAlertType] = OMIT,
        metadata: typing.Optional[typing.Dict[str, str]] = OMIT,
        triggers: typing.Optional[typing.Sequence[AlertTriggerWrite]] = OMIT,
        project_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[None]:
        """
        Update alert

        Parameters
        ----------
        id_ : str

        webhook : WebhookWrite

        id : typing.Optional[str]

        name : typing.Optional[str]

        enabled : typing.Optional[bool]

        alert_type : typing.Optional[AlertWriteAlertType]

        metadata : typing.Optional[typing.Dict[str, str]]

        triggers : typing.Optional[typing.Sequence[AlertTriggerWrite]]

        project_id : typing.Optional[str]
            Optional project scope for this alert. When set, the alert is scoped to the specified project. Do NOT also provide a 'scope:project' trigger config — the system will create it automatically from this field. Sending both project_id and a scope:project trigger config will result in an error.

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/private/alerts/{jsonable_encoder(id_)}",
            method="PUT",
            json={
                "id": id,
                "name": name,
                "enabled": enabled,
                "alert_type": alert_type,
                "metadata": metadata,
                "webhook": convert_and_respect_annotation_metadata(
                    object_=webhook, annotation=WebhookWrite, direction="write"
                ),
                "triggers": convert_and_respect_annotation_metadata(
                    object_=triggers, annotation=typing.Sequence[AlertTriggerWrite], direction="write"
                ),
                "project_id": project_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return HttpResponse(response=_response, data=None)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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_webhook_examples(
        self,
        *,
        alert_type: typing.Optional[GetWebhookExamplesRequestAlertType] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[WebhookExamples]:
        """
        Get webhook payload examples for all alert event types, optionally filtered by alert type

        Parameters
        ----------
        alert_type : typing.Optional[GetWebhookExamplesRequestAlertType]

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

        Returns
        -------
        HttpResponse[WebhookExamples]
            Webhook examples
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/private/alerts/webhooks/examples",
            method="GET",
            params={
                "alert_type": alert_type,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    WebhookExamples,
                    parse_obj_as(
                        type_=WebhookExamples,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def test_webhook(
        self,
        *,
        webhook: WebhookWrite,
        id: typing.Optional[str] = OMIT,
        name: typing.Optional[str] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        alert_type: typing.Optional[AlertWriteAlertType] = OMIT,
        metadata: typing.Optional[typing.Dict[str, str]] = OMIT,
        triggers: typing.Optional[typing.Sequence[AlertTriggerWrite]] = OMIT,
        project_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[WebhookTestResult]:
        """
        Test alert webhook

        Parameters
        ----------
        webhook : WebhookWrite

        id : typing.Optional[str]

        name : typing.Optional[str]

        enabled : typing.Optional[bool]

        alert_type : typing.Optional[AlertWriteAlertType]

        metadata : typing.Optional[typing.Dict[str, str]]

        triggers : typing.Optional[typing.Sequence[AlertTriggerWrite]]

        project_id : typing.Optional[str]
            Optional project scope for this alert. When set, the alert is scoped to the specified project. Do NOT also provide a 'scope:project' trigger config — the system will create it automatically from this field. Sending both project_id and a scope:project trigger config will result in an error.

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

        Returns
        -------
        HttpResponse[WebhookTestResult]
            Webhook test
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/private/alerts/webhooks/tests",
            method="POST",
            json={
                "id": id,
                "name": name,
                "enabled": enabled,
                "alert_type": alert_type,
                "metadata": metadata,
                "webhook": convert_and_respect_annotation_metadata(
                    object_=webhook, annotation=WebhookWrite, direction="write"
                ),
                "triggers": convert_and_respect_annotation_metadata(
                    object_=triggers, annotation=typing.Sequence[AlertTriggerWrite], direction="write"
                ),
                "project_id": project_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    WebhookTestResult,
                    parse_obj_as(
                        type_=WebhookTestResult,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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 AsyncRawAlertsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def find_alerts(
        self,
        *,
        page: typing.Optional[int] = None,
        size: typing.Optional[int] = None,
        sorting: typing.Optional[str] = None,
        filters: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AlertPagePublic]:
        """
        Find alerts

        Parameters
        ----------
        page : typing.Optional[int]

        size : typing.Optional[int]

        sorting : typing.Optional[str]

        filters : typing.Optional[str]

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

        Returns
        -------
        AsyncHttpResponse[AlertPagePublic]
            OK
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/private/alerts",
            method="GET",
            params={
                "page": page,
                "size": size,
                "sorting": sorting,
                "filters": filters,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AlertPagePublic,
                    parse_obj_as(
                        type_=AlertPagePublic,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def create_alert(
        self,
        *,
        webhook: WebhookWrite,
        id: typing.Optional[str] = OMIT,
        name: typing.Optional[str] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        alert_type: typing.Optional[AlertWriteAlertType] = OMIT,
        metadata: typing.Optional[typing.Dict[str, str]] = OMIT,
        triggers: typing.Optional[typing.Sequence[AlertTriggerWrite]] = OMIT,
        project_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[None]:
        """
        Create alert

        Parameters
        ----------
        webhook : WebhookWrite

        id : typing.Optional[str]

        name : typing.Optional[str]

        enabled : typing.Optional[bool]

        alert_type : typing.Optional[AlertWriteAlertType]

        metadata : typing.Optional[typing.Dict[str, str]]

        triggers : typing.Optional[typing.Sequence[AlertTriggerWrite]]

        project_id : typing.Optional[str]
            Optional project scope for this alert. When set, the alert is scoped to the specified project. Do NOT also provide a 'scope:project' trigger config — the system will create it automatically from this field. Sending both project_id and a scope:project trigger config will result in an error.

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/private/alerts",
            method="POST",
            json={
                "id": id,
                "name": name,
                "enabled": enabled,
                "alert_type": alert_type,
                "metadata": metadata,
                "webhook": convert_and_respect_annotation_metadata(
                    object_=webhook, annotation=WebhookWrite, direction="write"
                ),
                "triggers": convert_and_respect_annotation_metadata(
                    object_=triggers, annotation=typing.Sequence[AlertTriggerWrite], direction="write"
                ),
                "project_id": project_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return AsyncHttpResponse(response=_response, data=None)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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_alert_batch(
        self, *, ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[None]:
        """
        Delete multiple alerts by their IDs

        Parameters
        ----------
        ids : typing.Sequence[str]

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/private/alerts/delete",
            method="POST",
            json={
                "ids": ids,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return AsyncHttpResponse(response=_response, data=None)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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_alert_by_id(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[AlertPublic]:
        """
        Get Alert by id

        Parameters
        ----------
        id : str

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

        Returns
        -------
        AsyncHttpResponse[AlertPublic]
            Alert resource
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/private/alerts/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AlertPublic,
                    parse_obj_as(
                        type_=AlertPublic,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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_alert(
        self,
        id_: str,
        *,
        webhook: WebhookWrite,
        id: typing.Optional[str] = OMIT,
        name: typing.Optional[str] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        alert_type: typing.Optional[AlertWriteAlertType] = OMIT,
        metadata: typing.Optional[typing.Dict[str, str]] = OMIT,
        triggers: typing.Optional[typing.Sequence[AlertTriggerWrite]] = OMIT,
        project_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[None]:
        """
        Update alert

        Parameters
        ----------
        id_ : str

        webhook : WebhookWrite

        id : typing.Optional[str]

        name : typing.Optional[str]

        enabled : typing.Optional[bool]

        alert_type : typing.Optional[AlertWriteAlertType]

        metadata : typing.Optional[typing.Dict[str, str]]

        triggers : typing.Optional[typing.Sequence[AlertTriggerWrite]]

        project_id : typing.Optional[str]
            Optional project scope for this alert. When set, the alert is scoped to the specified project. Do NOT also provide a 'scope:project' trigger config — the system will create it automatically from this field. Sending both project_id and a scope:project trigger config will result in an error.

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/private/alerts/{jsonable_encoder(id_)}",
            method="PUT",
            json={
                "id": id,
                "name": name,
                "enabled": enabled,
                "alert_type": alert_type,
                "metadata": metadata,
                "webhook": convert_and_respect_annotation_metadata(
                    object_=webhook, annotation=WebhookWrite, direction="write"
                ),
                "triggers": convert_and_respect_annotation_metadata(
                    object_=triggers, annotation=typing.Sequence[AlertTriggerWrite], direction="write"
                ),
                "project_id": project_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return AsyncHttpResponse(response=_response, data=None)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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_webhook_examples(
        self,
        *,
        alert_type: typing.Optional[GetWebhookExamplesRequestAlertType] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[WebhookExamples]:
        """
        Get webhook payload examples for all alert event types, optionally filtered by alert type

        Parameters
        ----------
        alert_type : typing.Optional[GetWebhookExamplesRequestAlertType]

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

        Returns
        -------
        AsyncHttpResponse[WebhookExamples]
            Webhook examples
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/private/alerts/webhooks/examples",
            method="GET",
            params={
                "alert_type": alert_type,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    WebhookExamples,
                    parse_obj_as(
                        type_=WebhookExamples,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def test_webhook(
        self,
        *,
        webhook: WebhookWrite,
        id: typing.Optional[str] = OMIT,
        name: typing.Optional[str] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        alert_type: typing.Optional[AlertWriteAlertType] = OMIT,
        metadata: typing.Optional[typing.Dict[str, str]] = OMIT,
        triggers: typing.Optional[typing.Sequence[AlertTriggerWrite]] = OMIT,
        project_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[WebhookTestResult]:
        """
        Test alert webhook

        Parameters
        ----------
        webhook : WebhookWrite

        id : typing.Optional[str]

        name : typing.Optional[str]

        enabled : typing.Optional[bool]

        alert_type : typing.Optional[AlertWriteAlertType]

        metadata : typing.Optional[typing.Dict[str, str]]

        triggers : typing.Optional[typing.Sequence[AlertTriggerWrite]]

        project_id : typing.Optional[str]
            Optional project scope for this alert. When set, the alert is scoped to the specified project. Do NOT also provide a 'scope:project' trigger config — the system will create it automatically from this field. Sending both project_id and a scope:project trigger config will result in an error.

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

        Returns
        -------
        AsyncHttpResponse[WebhookTestResult]
            Webhook test
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/private/alerts/webhooks/tests",
            method="POST",
            json={
                "id": id,
                "name": name,
                "enabled": enabled,
                "alert_type": alert_type,
                "metadata": metadata,
                "webhook": convert_and_respect_annotation_metadata(
                    object_=webhook, annotation=WebhookWrite, direction="write"
                ),
                "triggers": convert_and_respect_annotation_metadata(
                    object_=triggers, annotation=typing.Sequence[AlertTriggerWrite], direction="write"
                ),
                "project_id": project_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    WebhookTestResult,
                    parse_obj_as(
                        type_=WebhookTestResult,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
