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

from __future__ import annotations
from .destination import Destination, DestinationTypedDict
from datetime import datetime
from enum import Enum
from outpost_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Any, Dict, Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict


class Status(str, Enum):
    r"""The attempt status."""

    SUCCESS = "success"
    FAILED = "failed"


class EventFullTypedDict(TypedDict):
    r"""Full event object with data (returned when include=event.data)."""

    id: NotRequired[str]
    tenant_id: NotRequired[str]
    r"""The tenant this event belongs to."""
    destination_id: NotRequired[str]
    r"""The destination this event was delivered to."""
    topic: NotRequired[str]
    time: NotRequired[datetime]
    r"""Time the event was received."""
    eligible_for_retry: NotRequired[bool]
    r"""Whether this event can be retried."""
    metadata: NotRequired[Nullable[Dict[str, str]]]
    data: NotRequired[Dict[str, Any]]
    r"""The event payload data."""


class EventFull(BaseModel):
    r"""Full event object with data (returned when include=event.data)."""

    id: Optional[str] = None

    tenant_id: Optional[str] = None
    r"""The tenant this event belongs to."""

    destination_id: Optional[str] = None
    r"""The destination this event was delivered to."""

    topic: Optional[str] = None

    time: Optional[datetime] = None
    r"""Time the event was received."""

    eligible_for_retry: Optional[bool] = None
    r"""Whether this event can be retried."""

    metadata: OptionalNullable[Dict[str, str]] = UNSET

    data: Optional[Dict[str, Any]] = None
    r"""The event payload data."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "id",
                "tenant_id",
                "destination_id",
                "topic",
                "time",
                "eligible_for_retry",
                "metadata",
                "data",
            ]
        )
        nullable_fields = set(["metadata"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


class EventSummaryTypedDict(TypedDict):
    r"""Event object without data (returned when include=event)."""

    id: NotRequired[str]
    tenant_id: NotRequired[str]
    r"""The tenant this event belongs to."""
    destination_id: NotRequired[str]
    r"""The destination this event was delivered to."""
    topic: NotRequired[str]
    time: NotRequired[datetime]
    r"""Time the event was received."""
    eligible_for_retry: NotRequired[bool]
    r"""Whether this event can be retried."""
    metadata: NotRequired[Nullable[Dict[str, str]]]


class EventSummary(BaseModel):
    r"""Event object without data (returned when include=event)."""

    id: Optional[str] = None

    tenant_id: Optional[str] = None
    r"""The tenant this event belongs to."""

    destination_id: Optional[str] = None
    r"""The destination this event was delivered to."""

    topic: Optional[str] = None

    time: Optional[datetime] = None
    r"""Time the event was received."""

    eligible_for_retry: Optional[bool] = None
    r"""Whether this event can be retried."""

    metadata: OptionalNullable[Dict[str, str]] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "id",
                "tenant_id",
                "destination_id",
                "topic",
                "time",
                "eligible_for_retry",
                "metadata",
            ]
        )
        nullable_fields = set(["metadata"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


EventUnionTypedDict = TypeAliasType(
    "EventUnionTypedDict", Union[EventSummaryTypedDict, EventFullTypedDict]
)
r"""The associated event object. Only present when include=event or include=event.data."""


EventUnion = TypeAliasType("EventUnion", Union[EventSummary, EventFull])
r"""The associated event object. Only present when include=event or include=event.data."""


class AttemptTypedDict(TypedDict):
    r"""An attempt represents a single delivery attempt of an event to a destination."""

    id: NotRequired[str]
    r"""Unique identifier for this attempt."""
    tenant_id: NotRequired[str]
    r"""The tenant this attempt belongs to."""
    status: NotRequired[Status]
    r"""The attempt status."""
    time: NotRequired[datetime]
    r"""Time the attempt was made."""
    code: NotRequired[str]
    r"""Response status code or error code."""
    response_data: NotRequired[Nullable[Dict[str, Any]]]
    r"""Response data from the attempt. Only included when include=response_data."""
    attempt_number: NotRequired[int]
    r"""The attempt number (1 for first attempt, 2+ for retries)."""
    manual: NotRequired[bool]
    r"""Whether this attempt was manually triggered (e.g., a retry initiated by a user)."""
    event_id: NotRequired[str]
    r"""The ID of the associated event."""
    destination_id: NotRequired[str]
    r"""The destination ID this attempt was sent to."""
    event: NotRequired[Nullable[EventUnionTypedDict]]
    r"""The associated event object. Only present when include=event or include=event.data."""
    destination: NotRequired[DestinationTypedDict]


class Attempt(BaseModel):
    r"""An attempt represents a single delivery attempt of an event to a destination."""

    id: Optional[str] = None
    r"""Unique identifier for this attempt."""

    tenant_id: Optional[str] = None
    r"""The tenant this attempt belongs to."""

    status: Optional[Status] = None
    r"""The attempt status."""

    time: Optional[datetime] = None
    r"""Time the attempt was made."""

    code: Optional[str] = None
    r"""Response status code or error code."""

    response_data: OptionalNullable[Dict[str, Any]] = UNSET
    r"""Response data from the attempt. Only included when include=response_data."""

    attempt_number: Optional[int] = None
    r"""The attempt number (1 for first attempt, 2+ for retries)."""

    manual: Optional[bool] = None
    r"""Whether this attempt was manually triggered (e.g., a retry initiated by a user)."""

    event_id: Optional[str] = None
    r"""The ID of the associated event."""

    destination_id: Optional[str] = None
    r"""The destination ID this attempt was sent to."""

    event: OptionalNullable[EventUnion] = UNSET
    r"""The associated event object. Only present when include=event or include=event.data."""

    destination: Optional[Destination] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "id",
                "tenant_id",
                "status",
                "time",
                "code",
                "response_data",
                "attempt_number",
                "manual",
                "event_id",
                "destination_id",
                "event",
                "destination",
            ]
        )
        nullable_fields = set(["response_data", "event"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m
