"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from .basesdk import BaseSDK
from outpost_sdk import errors, models, utils
from outpost_sdk._hooks import HookContext
from outpost_sdk.types import OptionalNullable, UNSET
from typing import Any, List, Mapping, Optional, Union


class Events(BaseSDK):
    r"""Operations related to event history and deliveries."""

    def list(
        self,
        *,
        tenant_id: Optional[str] = None,
        destination_id: Optional[
            Union[models.DestinationID, models.DestinationIDTypedDict]
        ] = None,
        status: Optional[models.ListTenantEventsStatus] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> List[models.Event]:
        r"""List Events

        Retrieves a list of events for the tenant, supporting cursor navigation (details TBD) and filtering.

        :param tenant_id: The ID of the tenant. Required when using AdminApiKey authentication.
        :param destination_id: Filter events by destination ID(s).
        :param status: Filter events by delivery status.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.ListTenantEventsRequest(
            tenant_id=tenant_id,
            destination_id=destination_id,
            status=status,
        )

        req = self._build_request(
            method="GET",
            path="/{tenant_id}/events",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            _globals=models.ListTenantEventsGlobals(
                tenant_id=self.sdk_configuration.globals.tenant_id,
            ),
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                base_url=base_url or "",
                operation_id="listTenantEvents",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "407",
                "408",
                "413",
                "414",
                "415",
                "422",
                "429",
                "431",
                "4XX",
                "500",
                "501",
                "502",
                "503",
                "504",
                "505",
                "506",
                "507",
                "508",
                "510",
                "511",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json(http_res.text, List[models.Event])
        if utils.match_response(http_res, ["401", "403", "407"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, "408", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.RateLimitedErrorData
            )
            raise errors.RateLimitedError(data=response_data)
        if utils.match_response(
            http_res, ["400", "413", "414", "415", "422", "431"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "504", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, ["501", "505"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.NotFoundErrorData
            )
            raise errors.NotFoundError(data=response_data)
        if utils.match_response(
            http_res, ["500", "502", "503", "506", "507", "508"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.InternalServerErrorData
            )
            raise errors.InternalServerError(data=response_data)
        if utils.match_response(http_res, "510", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "511", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, ["404", "4XX"], "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )

        content_type = http_res.headers.get("Content-Type")
        http_res_text = utils.stream_to_text(http_res)
        raise errors.APIError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res_text,
            http_res,
        )

    async def list_async(
        self,
        *,
        tenant_id: Optional[str] = None,
        destination_id: Optional[
            Union[models.DestinationID, models.DestinationIDTypedDict]
        ] = None,
        status: Optional[models.ListTenantEventsStatus] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> List[models.Event]:
        r"""List Events

        Retrieves a list of events for the tenant, supporting cursor navigation (details TBD) and filtering.

        :param tenant_id: The ID of the tenant. Required when using AdminApiKey authentication.
        :param destination_id: Filter events by destination ID(s).
        :param status: Filter events by delivery status.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.ListTenantEventsRequest(
            tenant_id=tenant_id,
            destination_id=destination_id,
            status=status,
        )

        req = self._build_request_async(
            method="GET",
            path="/{tenant_id}/events",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            _globals=models.ListTenantEventsGlobals(
                tenant_id=self.sdk_configuration.globals.tenant_id,
            ),
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                base_url=base_url or "",
                operation_id="listTenantEvents",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "407",
                "408",
                "413",
                "414",
                "415",
                "422",
                "429",
                "431",
                "4XX",
                "500",
                "501",
                "502",
                "503",
                "504",
                "505",
                "506",
                "507",
                "508",
                "510",
                "511",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json(http_res.text, List[models.Event])
        if utils.match_response(http_res, ["401", "403", "407"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, "408", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.RateLimitedErrorData
            )
            raise errors.RateLimitedError(data=response_data)
        if utils.match_response(
            http_res, ["400", "413", "414", "415", "422", "431"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "504", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, ["501", "505"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.NotFoundErrorData
            )
            raise errors.NotFoundError(data=response_data)
        if utils.match_response(
            http_res, ["500", "502", "503", "506", "507", "508"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.InternalServerErrorData
            )
            raise errors.InternalServerError(data=response_data)
        if utils.match_response(http_res, "510", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "511", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, ["404", "4XX"], "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )

        content_type = http_res.headers.get("Content-Type")
        http_res_text = await utils.stream_to_text_async(http_res)
        raise errors.APIError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res_text,
            http_res,
        )

    def get(
        self,
        *,
        event_id: str,
        tenant_id: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.Event:
        r"""Get Event

        Retrieves details for a specific event.

        :param event_id: The ID of the event.
        :param tenant_id: The ID of the tenant. Required when using AdminApiKey authentication.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetTenantEventRequest(
            tenant_id=tenant_id,
            event_id=event_id,
        )

        req = self._build_request(
            method="GET",
            path="/{tenant_id}/events/{event_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            _globals=models.GetTenantEventGlobals(
                tenant_id=self.sdk_configuration.globals.tenant_id,
            ),
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                base_url=base_url or "",
                operation_id="getTenantEvent",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "407",
                "408",
                "413",
                "414",
                "415",
                "422",
                "429",
                "431",
                "4XX",
                "500",
                "501",
                "502",
                "503",
                "504",
                "505",
                "506",
                "507",
                "508",
                "510",
                "511",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json(http_res.text, models.Event)
        if utils.match_response(http_res, ["401", "403", "407"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, "408", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.RateLimitedErrorData
            )
            raise errors.RateLimitedError(data=response_data)
        if utils.match_response(
            http_res, ["400", "413", "414", "415", "422", "431"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "504", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, ["501", "505"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.NotFoundErrorData
            )
            raise errors.NotFoundError(data=response_data)
        if utils.match_response(
            http_res, ["500", "502", "503", "506", "507", "508"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.InternalServerErrorData
            )
            raise errors.InternalServerError(data=response_data)
        if utils.match_response(http_res, "510", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "511", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, ["404", "4XX"], "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )

        content_type = http_res.headers.get("Content-Type")
        http_res_text = utils.stream_to_text(http_res)
        raise errors.APIError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res_text,
            http_res,
        )

    async def get_async(
        self,
        *,
        event_id: str,
        tenant_id: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.Event:
        r"""Get Event

        Retrieves details for a specific event.

        :param event_id: The ID of the event.
        :param tenant_id: The ID of the tenant. Required when using AdminApiKey authentication.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetTenantEventRequest(
            tenant_id=tenant_id,
            event_id=event_id,
        )

        req = self._build_request_async(
            method="GET",
            path="/{tenant_id}/events/{event_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            _globals=models.GetTenantEventGlobals(
                tenant_id=self.sdk_configuration.globals.tenant_id,
            ),
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                base_url=base_url or "",
                operation_id="getTenantEvent",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "407",
                "408",
                "413",
                "414",
                "415",
                "422",
                "429",
                "431",
                "4XX",
                "500",
                "501",
                "502",
                "503",
                "504",
                "505",
                "506",
                "507",
                "508",
                "510",
                "511",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json(http_res.text, models.Event)
        if utils.match_response(http_res, ["401", "403", "407"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, "408", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.RateLimitedErrorData
            )
            raise errors.RateLimitedError(data=response_data)
        if utils.match_response(
            http_res, ["400", "413", "414", "415", "422", "431"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "504", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, ["501", "505"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.NotFoundErrorData
            )
            raise errors.NotFoundError(data=response_data)
        if utils.match_response(
            http_res, ["500", "502", "503", "506", "507", "508"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.InternalServerErrorData
            )
            raise errors.InternalServerError(data=response_data)
        if utils.match_response(http_res, "510", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "511", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, ["404", "4XX"], "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )

        content_type = http_res.headers.get("Content-Type")
        http_res_text = await utils.stream_to_text_async(http_res)
        raise errors.APIError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res_text,
            http_res,
        )

    def list_deliveries(
        self,
        *,
        event_id: str,
        tenant_id: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> List[models.DeliveryAttempt]:
        r"""List Event Delivery Attempts

        Retrieves a list of delivery attempts for a specific event, including response details.

        :param event_id: The ID of the event.
        :param tenant_id: The ID of the tenant. Required when using AdminApiKey authentication.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.ListTenantEventDeliveriesRequest(
            tenant_id=tenant_id,
            event_id=event_id,
        )

        req = self._build_request(
            method="GET",
            path="/{tenant_id}/events/{event_id}/deliveries",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            _globals=models.ListTenantEventDeliveriesGlobals(
                tenant_id=self.sdk_configuration.globals.tenant_id,
            ),
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                base_url=base_url or "",
                operation_id="listTenantEventDeliveries",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "407",
                "408",
                "413",
                "414",
                "415",
                "422",
                "429",
                "431",
                "4XX",
                "500",
                "501",
                "502",
                "503",
                "504",
                "505",
                "506",
                "507",
                "508",
                "510",
                "511",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json(http_res.text, List[models.DeliveryAttempt])
        if utils.match_response(http_res, ["401", "403", "407"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, "408", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.RateLimitedErrorData
            )
            raise errors.RateLimitedError(data=response_data)
        if utils.match_response(
            http_res, ["400", "413", "414", "415", "422", "431"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "504", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, ["501", "505"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.NotFoundErrorData
            )
            raise errors.NotFoundError(data=response_data)
        if utils.match_response(
            http_res, ["500", "502", "503", "506", "507", "508"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.InternalServerErrorData
            )
            raise errors.InternalServerError(data=response_data)
        if utils.match_response(http_res, "510", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "511", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, ["404", "4XX"], "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )

        content_type = http_res.headers.get("Content-Type")
        http_res_text = utils.stream_to_text(http_res)
        raise errors.APIError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res_text,
            http_res,
        )

    async def list_deliveries_async(
        self,
        *,
        event_id: str,
        tenant_id: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> List[models.DeliveryAttempt]:
        r"""List Event Delivery Attempts

        Retrieves a list of delivery attempts for a specific event, including response details.

        :param event_id: The ID of the event.
        :param tenant_id: The ID of the tenant. Required when using AdminApiKey authentication.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.ListTenantEventDeliveriesRequest(
            tenant_id=tenant_id,
            event_id=event_id,
        )

        req = self._build_request_async(
            method="GET",
            path="/{tenant_id}/events/{event_id}/deliveries",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            _globals=models.ListTenantEventDeliveriesGlobals(
                tenant_id=self.sdk_configuration.globals.tenant_id,
            ),
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                base_url=base_url or "",
                operation_id="listTenantEventDeliveries",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "407",
                "408",
                "413",
                "414",
                "415",
                "422",
                "429",
                "431",
                "4XX",
                "500",
                "501",
                "502",
                "503",
                "504",
                "505",
                "506",
                "507",
                "508",
                "510",
                "511",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json(http_res.text, List[models.DeliveryAttempt])
        if utils.match_response(http_res, ["401", "403", "407"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, "408", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.RateLimitedErrorData
            )
            raise errors.RateLimitedError(data=response_data)
        if utils.match_response(
            http_res, ["400", "413", "414", "415", "422", "431"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "504", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, ["501", "505"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.NotFoundErrorData
            )
            raise errors.NotFoundError(data=response_data)
        if utils.match_response(
            http_res, ["500", "502", "503", "506", "507", "508"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.InternalServerErrorData
            )
            raise errors.InternalServerError(data=response_data)
        if utils.match_response(http_res, "510", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "511", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, ["404", "4XX"], "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )

        content_type = http_res.headers.get("Content-Type")
        http_res_text = await utils.stream_to_text_async(http_res)
        raise errors.APIError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res_text,
            http_res,
        )

    def list_by_destination(
        self,
        *,
        destination_id: str,
        tenant_id: Optional[str] = None,
        status: Optional[models.ListTenantEventsByDestinationStatus] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> List[models.Event]:
        r"""List Events by Destination

        Retrieves events associated with a specific destination for the tenant.

        :param destination_id: The ID of the destination.
        :param tenant_id: The ID of the tenant. Required when using AdminApiKey authentication.
        :param status: Filter events by delivery status.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.ListTenantEventsByDestinationRequest(
            tenant_id=tenant_id,
            destination_id=destination_id,
            status=status,
        )

        req = self._build_request(
            method="GET",
            path="/{tenant_id}/destinations/{destination_id}/events",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            _globals=models.ListTenantEventsByDestinationGlobals(
                tenant_id=self.sdk_configuration.globals.tenant_id,
            ),
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                base_url=base_url or "",
                operation_id="listTenantEventsByDestination",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "407",
                "408",
                "413",
                "414",
                "415",
                "422",
                "429",
                "431",
                "4XX",
                "500",
                "501",
                "502",
                "503",
                "504",
                "505",
                "506",
                "507",
                "508",
                "510",
                "511",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json(http_res.text, List[models.Event])
        if utils.match_response(http_res, ["401", "403", "407"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, "408", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.RateLimitedErrorData
            )
            raise errors.RateLimitedError(data=response_data)
        if utils.match_response(
            http_res, ["400", "413", "414", "415", "422", "431"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "504", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, ["501", "505"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.NotFoundErrorData
            )
            raise errors.NotFoundError(data=response_data)
        if utils.match_response(
            http_res, ["500", "502", "503", "506", "507", "508"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.InternalServerErrorData
            )
            raise errors.InternalServerError(data=response_data)
        if utils.match_response(http_res, "510", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "511", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, ["404", "4XX"], "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )

        content_type = http_res.headers.get("Content-Type")
        http_res_text = utils.stream_to_text(http_res)
        raise errors.APIError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res_text,
            http_res,
        )

    async def list_by_destination_async(
        self,
        *,
        destination_id: str,
        tenant_id: Optional[str] = None,
        status: Optional[models.ListTenantEventsByDestinationStatus] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> List[models.Event]:
        r"""List Events by Destination

        Retrieves events associated with a specific destination for the tenant.

        :param destination_id: The ID of the destination.
        :param tenant_id: The ID of the tenant. Required when using AdminApiKey authentication.
        :param status: Filter events by delivery status.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.ListTenantEventsByDestinationRequest(
            tenant_id=tenant_id,
            destination_id=destination_id,
            status=status,
        )

        req = self._build_request_async(
            method="GET",
            path="/{tenant_id}/destinations/{destination_id}/events",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            _globals=models.ListTenantEventsByDestinationGlobals(
                tenant_id=self.sdk_configuration.globals.tenant_id,
            ),
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                base_url=base_url or "",
                operation_id="listTenantEventsByDestination",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "407",
                "408",
                "413",
                "414",
                "415",
                "422",
                "429",
                "431",
                "4XX",
                "500",
                "501",
                "502",
                "503",
                "504",
                "505",
                "506",
                "507",
                "508",
                "510",
                "511",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json(http_res.text, List[models.Event])
        if utils.match_response(http_res, ["401", "403", "407"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, "408", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.RateLimitedErrorData
            )
            raise errors.RateLimitedError(data=response_data)
        if utils.match_response(
            http_res, ["400", "413", "414", "415", "422", "431"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "504", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, ["501", "505"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.NotFoundErrorData
            )
            raise errors.NotFoundError(data=response_data)
        if utils.match_response(
            http_res, ["500", "502", "503", "506", "507", "508"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.InternalServerErrorData
            )
            raise errors.InternalServerError(data=response_data)
        if utils.match_response(http_res, "510", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "511", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, ["404", "4XX"], "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )

        content_type = http_res.headers.get("Content-Type")
        http_res_text = await utils.stream_to_text_async(http_res)
        raise errors.APIError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res_text,
            http_res,
        )

    def get_by_destination(
        self,
        *,
        destination_id: str,
        event_id: str,
        tenant_id: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.Event:
        r"""Get Event by Destination

        Retrieves a specific event associated with a specific destination for the tenant.

        :param destination_id: The ID of the destination.
        :param event_id: The ID of the event.
        :param tenant_id: The ID of the tenant. Required when using AdminApiKey authentication.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetTenantEventByDestinationRequest(
            tenant_id=tenant_id,
            destination_id=destination_id,
            event_id=event_id,
        )

        req = self._build_request(
            method="GET",
            path="/{tenant_id}/destinations/{destination_id}/events/{event_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            _globals=models.GetTenantEventByDestinationGlobals(
                tenant_id=self.sdk_configuration.globals.tenant_id,
            ),
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                base_url=base_url or "",
                operation_id="getTenantEventByDestination",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "407",
                "408",
                "413",
                "414",
                "415",
                "422",
                "429",
                "431",
                "4XX",
                "500",
                "501",
                "502",
                "503",
                "504",
                "505",
                "506",
                "507",
                "508",
                "510",
                "511",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json(http_res.text, models.Event)
        if utils.match_response(http_res, ["401", "403", "407"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, "408", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.RateLimitedErrorData
            )
            raise errors.RateLimitedError(data=response_data)
        if utils.match_response(
            http_res, ["400", "413", "414", "415", "422", "431"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "504", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, ["501", "505"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.NotFoundErrorData
            )
            raise errors.NotFoundError(data=response_data)
        if utils.match_response(
            http_res, ["500", "502", "503", "506", "507", "508"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.InternalServerErrorData
            )
            raise errors.InternalServerError(data=response_data)
        if utils.match_response(http_res, "510", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "511", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, ["404", "4XX"], "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )

        content_type = http_res.headers.get("Content-Type")
        http_res_text = utils.stream_to_text(http_res)
        raise errors.APIError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res_text,
            http_res,
        )

    async def get_by_destination_async(
        self,
        *,
        destination_id: str,
        event_id: str,
        tenant_id: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.Event:
        r"""Get Event by Destination

        Retrieves a specific event associated with a specific destination for the tenant.

        :param destination_id: The ID of the destination.
        :param event_id: The ID of the event.
        :param tenant_id: The ID of the tenant. Required when using AdminApiKey authentication.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetTenantEventByDestinationRequest(
            tenant_id=tenant_id,
            destination_id=destination_id,
            event_id=event_id,
        )

        req = self._build_request_async(
            method="GET",
            path="/{tenant_id}/destinations/{destination_id}/events/{event_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            _globals=models.GetTenantEventByDestinationGlobals(
                tenant_id=self.sdk_configuration.globals.tenant_id,
            ),
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                base_url=base_url or "",
                operation_id="getTenantEventByDestination",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "407",
                "408",
                "413",
                "414",
                "415",
                "422",
                "429",
                "431",
                "4XX",
                "500",
                "501",
                "502",
                "503",
                "504",
                "505",
                "506",
                "507",
                "508",
                "510",
                "511",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json(http_res.text, models.Event)
        if utils.match_response(http_res, ["401", "403", "407"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, "408", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.RateLimitedErrorData
            )
            raise errors.RateLimitedError(data=response_data)
        if utils.match_response(
            http_res, ["400", "413", "414", "415", "422", "431"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "504", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, ["501", "505"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.NotFoundErrorData
            )
            raise errors.NotFoundError(data=response_data)
        if utils.match_response(
            http_res, ["500", "502", "503", "506", "507", "508"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.InternalServerErrorData
            )
            raise errors.InternalServerError(data=response_data)
        if utils.match_response(http_res, "510", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "511", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, ["404", "4XX"], "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )

        content_type = http_res.headers.get("Content-Type")
        http_res_text = await utils.stream_to_text_async(http_res)
        raise errors.APIError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res_text,
            http_res,
        )

    def retry(
        self,
        *,
        destination_id: str,
        event_id: str,
        tenant_id: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ):
        r"""Retry Event Delivery

        Triggers a retry for a failed event delivery.

        :param destination_id: The ID of the destination.
        :param event_id: The ID of the event to retry.
        :param tenant_id: The ID of the tenant. Required when using AdminApiKey authentication.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.RetryTenantEventRequest(
            tenant_id=tenant_id,
            destination_id=destination_id,
            event_id=event_id,
        )

        req = self._build_request(
            method="POST",
            path="/{tenant_id}/destinations/{destination_id}/events/{event_id}/retry",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            _globals=models.RetryTenantEventGlobals(
                tenant_id=self.sdk_configuration.globals.tenant_id,
            ),
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                base_url=base_url or "",
                operation_id="retryTenantEvent",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "407",
                "408",
                "409",
                "413",
                "414",
                "415",
                "422",
                "429",
                "431",
                "4XX",
                "500",
                "501",
                "502",
                "503",
                "504",
                "505",
                "506",
                "507",
                "508",
                "510",
                "511",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "202", "*"):
            return
        if utils.match_response(http_res, ["401", "403", "407"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, "408", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.RateLimitedErrorData
            )
            raise errors.RateLimitedError(data=response_data)
        if utils.match_response(
            http_res, ["400", "413", "414", "415", "422", "431"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "504", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, ["501", "505"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.NotFoundErrorData
            )
            raise errors.NotFoundError(data=response_data)
        if utils.match_response(
            http_res, ["500", "502", "503", "506", "507", "508"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.InternalServerErrorData
            )
            raise errors.InternalServerError(data=response_data)
        if utils.match_response(http_res, "510", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "511", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, ["404", "409", "4XX"], "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )

        content_type = http_res.headers.get("Content-Type")
        http_res_text = utils.stream_to_text(http_res)
        raise errors.APIError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res_text,
            http_res,
        )

    async def retry_async(
        self,
        *,
        destination_id: str,
        event_id: str,
        tenant_id: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ):
        r"""Retry Event Delivery

        Triggers a retry for a failed event delivery.

        :param destination_id: The ID of the destination.
        :param event_id: The ID of the event to retry.
        :param tenant_id: The ID of the tenant. Required when using AdminApiKey authentication.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.RetryTenantEventRequest(
            tenant_id=tenant_id,
            destination_id=destination_id,
            event_id=event_id,
        )

        req = self._build_request_async(
            method="POST",
            path="/{tenant_id}/destinations/{destination_id}/events/{event_id}/retry",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            _globals=models.RetryTenantEventGlobals(
                tenant_id=self.sdk_configuration.globals.tenant_id,
            ),
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                base_url=base_url or "",
                operation_id="retryTenantEvent",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "407",
                "408",
                "409",
                "413",
                "414",
                "415",
                "422",
                "429",
                "431",
                "4XX",
                "500",
                "501",
                "502",
                "503",
                "504",
                "505",
                "506",
                "507",
                "508",
                "510",
                "511",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "202", "*"):
            return
        if utils.match_response(http_res, ["401", "403", "407"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, "408", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.RateLimitedErrorData
            )
            raise errors.RateLimitedError(data=response_data)
        if utils.match_response(
            http_res, ["400", "413", "414", "415", "422", "431"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "504", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.TimeoutErrorTData
            )
            raise errors.TimeoutErrorT(data=response_data)
        if utils.match_response(http_res, ["501", "505"], "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.NotFoundErrorData
            )
            raise errors.NotFoundError(data=response_data)
        if utils.match_response(
            http_res, ["500", "502", "503", "506", "507", "508"], "application/json"
        ):
            response_data = utils.unmarshal_json(
                http_res.text, errors.InternalServerErrorData
            )
            raise errors.InternalServerError(data=response_data)
        if utils.match_response(http_res, "510", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.BadRequestErrorData
            )
            raise errors.BadRequestError(data=response_data)
        if utils.match_response(http_res, "511", "application/json"):
            response_data = utils.unmarshal_json(
                http_res.text, errors.UnauthorizedErrorData
            )
            raise errors.UnauthorizedError(data=response_data)
        if utils.match_response(http_res, ["404", "409", "4XX"], "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError(
                "API error occurred", http_res.status_code, http_res_text, http_res
            )

        content_type = http_res.headers.get("Content-Type")
        http_res_text = await utils.stream_to_text_async(http_res)
        raise errors.APIError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res_text,
            http_res,
        )
