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

from __future__ import annotations
from .workflowexecutiontraceevent import (
    WorkflowExecutionTraceEvent,
    WorkflowExecutionTraceEventTypedDict,
)
from .workflowexecutiontracesummaryattributesvalues import (
    WorkflowExecutionTraceSummaryAttributesValues,
    WorkflowExecutionTraceSummaryAttributesValuesTypedDict,
)
from mistralai.client.types import BaseModel, Nullable, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class WorkflowExecutionTraceSummarySpanTypedDict(TypedDict):
    span_id: str
    r"""The ID of the span"""
    name: str
    r"""The name of the span"""
    start_time_unix_nano: int
    r"""The start time of the span in nanoseconds since the Unix epoch"""
    end_time_unix_nano: Nullable[int]
    r"""The end time of the span in nanoseconds since the Unix epoch"""
    attributes: Dict[
        str, Nullable[WorkflowExecutionTraceSummaryAttributesValuesTypedDict]
    ]
    r"""The attributes of the span"""
    events: List[WorkflowExecutionTraceEventTypedDict]
    r"""The events of the span"""
    children: NotRequired[List[WorkflowExecutionTraceSummarySpanTypedDict]]
    r"""The child spans of the span"""


class WorkflowExecutionTraceSummarySpan(BaseModel):
    span_id: str
    r"""The ID of the span"""

    name: str
    r"""The name of the span"""

    start_time_unix_nano: int
    r"""The start time of the span in nanoseconds since the Unix epoch"""

    end_time_unix_nano: Nullable[int]
    r"""The end time of the span in nanoseconds since the Unix epoch"""

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

    events: List[WorkflowExecutionTraceEvent]
    r"""The events of the span"""

    children: Optional[List[WorkflowExecutionTraceSummarySpan]] = None
    r"""The child spans of the span"""

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