"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: 6ea7078aaca3

from __future__ import annotations
from .eventprogressstatus import EventProgressStatus
from .eventtype import EventType
from .workflowexecutiontracesummaryattributesvalues import (
    WorkflowExecutionTraceSummaryAttributesValues,
    WorkflowExecutionTraceSummaryAttributesValuesTypedDict,
)
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import NotRequired, TypedDict


class WorkflowExecutionProgressTraceEventTypedDict(TypedDict):
    name: str
    r"""Name of the event"""
    id: str
    r"""The ID of the event"""
    timestamp_unix_nano: int
    r"""The timestamp of the event in nanoseconds since the Unix epoch"""
    attributes: Dict[
        str, Nullable[WorkflowExecutionTraceSummaryAttributesValuesTypedDict]
    ]
    r"""The attributes of the event"""
    start_time_unix_ms: int
    r"""The start time of the event in milliseconds since the Unix epoch"""
    type: NotRequired[EventType]
    internal: NotRequired[bool]
    r"""Whether the event is internal"""
    status: NotRequired[EventProgressStatus]
    end_time_unix_ms: NotRequired[Nullable[int]]
    r"""The end time of the event in milliseconds since the Unix epoch"""
    error: NotRequired[Nullable[str]]
    r"""The error message, if any"""


class WorkflowExecutionProgressTraceEvent(BaseModel):
    name: str
    r"""Name of the event"""

    id: str
    r"""The ID of the event"""

    timestamp_unix_nano: int
    r"""The timestamp of the event in nanoseconds since the Unix epoch"""

    attributes: Dict[str, Nullable[WorkflowExecutionTraceSummaryAttributesValues]]
    r"""The attributes of the event"""

    start_time_unix_ms: int
    r"""The start time of the event in milliseconds since the Unix epoch"""

    type: Optional[EventType] = None

    internal: Optional[bool] = False
    r"""Whether the event is internal"""

    status: Optional[EventProgressStatus] = None

    end_time_unix_ms: OptionalNullable[int] = UNSET
    r"""The end time of the event in milliseconds since the Unix epoch"""

    error: OptionalNullable[str] = UNSET
    r"""The error message, if any"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["type", "internal", "status", "end_time_unix_ms", "error"]
        )
        nullable_fields = set(["end_time_unix_ms", "error"])
        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))
            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
