"""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 Any, Dict, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class IngestEventRequestTypedDict(TypedDict):
    type: str
    r"""CloudEvents type. Must match an eventType configured on a BillableMetric."""
    source: str
    r"""Event source URI identifying the application."""
    subject: str
    r"""Customer or entity ID this event relates to."""
    data: Dict[str, Any]
    r"""Event payload containing the metering data."""
    namespace: NotRequired[str]
    r"""Organization/merchant ID. Defaults to the authenticated user's organization. Platform users can specify a different organization."""
    timestamp: NotRequired[datetime]
    r"""Event timestamp. Defaults to server time if not provided."""
    idempotency_key: NotRequired[str]
    r"""User-provided deduplication key. If not provided, a unique key is generated."""


class IngestEventRequest(BaseModel):
    type: str
    r"""CloudEvents type. Must match an eventType configured on a BillableMetric."""

    source: str
    r"""Event source URI identifying the application."""

    subject: str
    r"""Customer or entity ID this event relates to."""

    data: Dict[str, Any]
    r"""Event payload containing the metering data."""

    namespace: Optional[str] = None
    r"""Organization/merchant ID. Defaults to the authenticated user's organization. Platform users can specify a different organization."""

    timestamp: Optional[datetime] = None
    r"""Event timestamp. Defaults to server time if not provided."""

    idempotency_key: Annotated[
        Optional[str], pydantic.Field(alias="idempotencyKey")
    ] = None
    r"""User-provided deduplication key. If not provided, a unique key is generated."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["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)

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

        return m


try:
    IngestEventRequest.model_rebuild()
except NameError:
    pass
