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

from __future__ import annotations
from .timelineeventtype import TimelineEventType
from .value import Value, ValueTypedDict
from datetime import datetime
from factify.types import BaseModel, Nullable, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import NotRequired, TypedDict


class TimelineEventTypedDict(TypedDict):
    event_id: NotRequired[str]
    event_type: NotRequired[TimelineEventType]
    occurred_at: NotRequired[datetime]
    payload: NotRequired[Dict[str, Nullable[ValueTypedDict]]]
    r"""`Struct` represents a structured data value, consisting of fields
    which map to dynamically typed values. In some languages, `Struct`
    might be supported by a native representation. For example, in
    scripting languages like JS a struct is represented as an
    object. The details of that representation are described together
    with the proto support for the language.

    The JSON representation for `Struct` is JSON object.
    """


class TimelineEvent(BaseModel):
    event_id: Optional[str] = None

    event_type: Optional[TimelineEventType] = None

    occurred_at: Optional[datetime] = None

    payload: Optional[Dict[str, Nullable[Value]]] = None
    r"""`Struct` represents a structured data value, consisting of fields
    which map to dynamically typed values. In some languages, `Struct`
    might be supported by a native representation. For example, in
    scripting languages like JS a struct is represented as an
    object. The details of that representation are described together
    with the proto support for the language.

    The JSON representation for `Struct` is JSON object.
    """

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