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

from __future__ import annotations
from datetime import datetime
from outpost_sdk.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Any, Dict, Optional
from typing_extensions import NotRequired, TypedDict


class PublishRequestTypedDict(TypedDict):
    data: Dict[str, Any]
    r"""Any JSON payload for the event data."""
    id: NotRequired[str]
    r"""Optional. A unique identifier for the event. If not provided, a UUID will be generated."""
    tenant_id: NotRequired[str]
    r"""The ID of the tenant to publish for."""
    destination_id: NotRequired[str]
    r"""Optional. Route event to a specific destination."""
    topic: NotRequired[str]
    r"""Topic name for the event. Required if Outpost has been configured with topics."""
    eligible_for_retry: NotRequired[bool]
    r"""Should event delivery be retried on failure."""
    time: NotRequired[datetime]
    r"""Optional. Custom timestamp for the event. If not provided, defaults to the current time."""
    metadata: NotRequired[Dict[str, str]]
    r"""Any key-value string pairs for metadata."""


class PublishRequest(BaseModel):
    data: Dict[str, Any]
    r"""Any JSON payload for the event data."""

    id: Optional[str] = None
    r"""Optional. A unique identifier for the event. If not provided, a UUID will be generated."""

    tenant_id: Optional[str] = None
    r"""The ID of the tenant to publish for."""

    destination_id: Optional[str] = None
    r"""Optional. Route event to a specific destination."""

    topic: Optional[str] = None
    r"""Topic name for the event. Required if Outpost has been configured with topics."""

    eligible_for_retry: Optional[bool] = None
    r"""Should event delivery be retried on failure."""

    time: Optional[datetime] = None
    r"""Optional. Custom timestamp for the event. If not provided, defaults to the current time."""

    metadata: Optional[Dict[str, str]] = None
    r"""Any key-value string pairs for metadata."""

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

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

        return m
