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

from __future__ import annotations
from datetime import datetime
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


EventResponseObject = Literal["event",]


class EventResponseTypedDict(TypedDict):
    id: NotRequired[str]
    r"""Server-generated event ID."""
    object: NotRequired[EventResponseObject]
    type: NotRequired[str]
    source: NotRequired[str]
    subject: NotRequired[str]
    namespace: NotRequired[str]
    timestamp: NotRequired[datetime]
    idempotency_key: NotRequired[str]


class EventResponse(BaseModel):
    id: Optional[str] = None
    r"""Server-generated event ID."""

    object: Optional[EventResponseObject] = "event"

    type: Optional[str] = None

    source: Optional[str] = None

    subject: Optional[str] = None

    namespace: Optional[str] = None

    timestamp: Optional[datetime] = None

    idempotency_key: Annotated[
        Optional[str], pydantic.Field(alias="idempotencyKey")
    ] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "id",
                "object",
                "type",
                "source",
                "subject",
                "namespace",
                "timestamp",
                "idempotencyKey",
            ]
        )
        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))

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

        return m


try:
    EventResponse.model_rebuild()
except NameError:
    pass
