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

from __future__ import annotations
from datetime import datetime
from pydantic import model_serializer
from syllable_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from typing_extensions import NotRequired, TypedDict


class AttributesTypedDict(TypedDict):
    pass


class Attributes(BaseModel):
    pass


class EventTypedDict(TypedDict):
    r"""An event represents a specific occurrence during a session."""

    timestamp: datetime
    r"""Timestamp at which the event occurred"""
    session_id: NotRequired[Nullable[str]]
    r"""ID of the session in which the event occurred"""
    conversation_id: NotRequired[Nullable[str]]
    r"""ID of the conversation associated with the session in which the event occurred"""
    source: NotRequired[Nullable[str]]
    r"""Source of the event (either a tool call or an LLM prompt)"""
    source_id: NotRequired[Nullable[str]]
    r"""ID of the source of the event (either a tool ID or a prompt ID)"""
    category: NotRequired[Nullable[str]]
    r"""Broad categorization of the event"""
    type: NotRequired[Nullable[str]]
    r"""More specific class of the event"""
    user_id: NotRequired[Nullable[str]]
    r"""ID of the user interacting with the system when the event occurred (e.g., their       phone number)"""
    description: NotRequired[Nullable[str]]
    r"""Human-readable description of the event"""
    attributes: NotRequired[Nullable[AttributesTypedDict]]
    r"""Arbitrary additional metadata for the event"""


class Event(BaseModel):
    r"""An event represents a specific occurrence during a session."""

    timestamp: datetime
    r"""Timestamp at which the event occurred"""

    session_id: OptionalNullable[str] = UNSET
    r"""ID of the session in which the event occurred"""

    conversation_id: OptionalNullable[str] = UNSET
    r"""ID of the conversation associated with the session in which the event occurred"""

    source: OptionalNullable[str] = UNSET
    r"""Source of the event (either a tool call or an LLM prompt)"""

    source_id: OptionalNullable[str] = UNSET
    r"""ID of the source of the event (either a tool ID or a prompt ID)"""

    category: OptionalNullable[str] = UNSET
    r"""Broad categorization of the event"""

    type: OptionalNullable[str] = UNSET
    r"""More specific class of the event"""

    user_id: OptionalNullable[str] = UNSET
    r"""ID of the user interacting with the system when the event occurred (e.g., their       phone number)"""

    description: OptionalNullable[str] = UNSET
    r"""Human-readable description of the event"""

    attributes: OptionalNullable[Attributes] = UNSET
    r"""Arbitrary additional metadata for the event"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "session_id",
                "conversation_id",
                "source",
                "source_id",
                "category",
                "type",
                "user_id",
                "description",
                "attributes",
            ]
        )
        nullable_fields = set(
            [
                "session_id",
                "conversation_id",
                "source",
                "source_id",
                "category",
                "type",
                "user_id",
                "description",
                "attributes",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

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

        return m
