"""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, UnrecognizedStr
import pydantic
from pydantic import model_serializer
from typing import Any, Dict, List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


SourceEventStatus = Union[
    Literal[
        "pending",
        "processed",
        "failed",
        "rejected",
    ],
    UnrecognizedStr,
]


class SourceEventTypedDict(TypedDict):
    id: str
    r"""Unique identifier for a source event"""
    created_at: datetime
    external_event_id: str
    raw_data: Dict[str, Any]
    source_id: str
    r"""Unique identifier for a source"""
    status: SourceEventStatus
    updated_at: datetime
    customer_id: NotRequired[str]
    r"""The customer associated with this source event"""
    error_message: NotRequired[str]
    processed_at: NotRequired[datetime]
    processed_by: NotRequired[str]
    subscription_id: NotRequired[str]
    r"""The subscription associated with this source event"""
    usage_event_ids: NotRequired[List[str]]


class SourceEvent(BaseModel):
    id: str
    r"""Unique identifier for a source event"""

    created_at: Annotated[datetime, pydantic.Field(alias="createdAt")]

    external_event_id: Annotated[str, pydantic.Field(alias="externalEventId")]

    raw_data: Annotated[Dict[str, Any], pydantic.Field(alias="rawData")]

    source_id: Annotated[str, pydantic.Field(alias="sourceId")]
    r"""Unique identifier for a source"""

    status: SourceEventStatus

    updated_at: Annotated[datetime, pydantic.Field(alias="updatedAt")]

    customer_id: Annotated[Optional[str], pydantic.Field(alias="customerId")] = None
    r"""The customer associated with this source event"""

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

    processed_at: Annotated[Optional[datetime], pydantic.Field(alias="processedAt")] = (
        None
    )

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

    subscription_id: Annotated[
        Optional[str], pydantic.Field(alias="subscriptionId")
    ] = None
    r"""The subscription associated with this source event"""

    usage_event_ids: Annotated[
        Optional[List[str]], pydantic.Field(alias="usageEventIds")
    ] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "customerId",
                "errorMessage",
                "processedAt",
                "processedBy",
                "subscriptionId",
                "usageEventIds",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

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

        return m


try:
    SourceEvent.model_rebuild()
except NameError:
    pass
