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

from __future__ import annotations
from .tempotraceattribute import TempoTraceAttribute, TempoTraceAttributeTypedDict
from .tempotraceevent import TempoTraceEvent, TempoTraceEventTypedDict
from .tempotracescopekind import TempoTraceScopeKind
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class TempoTraceSpanTypedDict(TypedDict):
    trace_id: str
    r"""The trace ID of the scope"""
    span_id: str
    r"""The span ID of the scope"""
    name: str
    r"""The name of the scope"""
    kind: TempoTraceScopeKind
    start_time_unix_nano: str
    r"""The start time of the scope in Unix nano"""
    end_time_unix_nano: str
    r"""The end time of the scope in Unix nano"""
    parent_span_id: NotRequired[Nullable[str]]
    r"""The parent span ID of the scope"""
    attributes: NotRequired[List[TempoTraceAttributeTypedDict]]
    r"""The attributes of the scope"""
    events: NotRequired[List[TempoTraceEventTypedDict]]
    r"""The events of the scope"""


class TempoTraceSpan(BaseModel):
    trace_id: Annotated[str, pydantic.Field(alias="traceId")]
    r"""The trace ID of the scope"""

    span_id: Annotated[str, pydantic.Field(alias="spanId")]
    r"""The span ID of the scope"""

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

    kind: TempoTraceScopeKind

    start_time_unix_nano: Annotated[str, pydantic.Field(alias="startTimeUnixNano")]
    r"""The start time of the scope in Unix nano"""

    end_time_unix_nano: Annotated[str, pydantic.Field(alias="endTimeUnixNano")]
    r"""The end time of the scope in Unix nano"""

    parent_span_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="parentSpanId")
    ] = UNSET
    r"""The parent span ID of the scope"""

    attributes: Optional[List[TempoTraceAttribute]] = None
    r"""The attributes of the scope"""

    events: Optional[List[TempoTraceEvent]] = None
    r"""The events of the scope"""

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


try:
    TempoTraceSpan.model_rebuild()
except NameError:
    pass
