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

from __future__ import annotations
from .tempogettraceresponse import TempoGetTraceResponse, TempoGetTraceResponseTypedDict
from .workflowexecutionstatus import WorkflowExecutionStatus
from datetime import datetime
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Any
from typing_extensions import NotRequired, TypedDict


class WorkflowExecutionTraceOTelResponseTypedDict(TypedDict):
    workflow_name: str
    r"""The name of the workflow"""
    execution_id: str
    r"""The ID of the workflow execution"""
    root_execution_id: str
    r"""The root execution ID of the workflow execution"""
    status: Nullable[WorkflowExecutionStatus]
    r"""The status of the workflow execution"""
    start_time: datetime
    r"""The start time of the workflow execution"""
    end_time: Nullable[datetime]
    r"""The end time of the workflow execution, if available"""
    result: Nullable[Any]
    r"""The result of the workflow execution, if available"""
    data_source: str
    r"""The data source of the trace"""
    parent_execution_id: NotRequired[Nullable[str]]
    r"""The parent execution ID of the workflow execution"""
    run_id: NotRequired[Nullable[str]]
    r"""The unique run identifier (database UUID)"""
    total_duration_ms: NotRequired[Nullable[int]]
    r"""The total duration of the trace in milliseconds"""
    otel_trace_id: NotRequired[Nullable[str]]
    r"""The ID of the trace"""
    otel_trace_data: NotRequired[Nullable[TempoGetTraceResponseTypedDict]]
    r"""The raw OpenTelemetry trace data"""


class WorkflowExecutionTraceOTelResponse(BaseModel):
    workflow_name: str
    r"""The name of the workflow"""

    execution_id: str
    r"""The ID of the workflow execution"""

    root_execution_id: str
    r"""The root execution ID of the workflow execution"""

    status: Nullable[WorkflowExecutionStatus]
    r"""The status of the workflow execution"""

    start_time: datetime
    r"""The start time of the workflow execution"""

    end_time: Nullable[datetime]
    r"""The end time of the workflow execution, if available"""

    result: Nullable[Any]
    r"""The result of the workflow execution, if available"""

    data_source: str
    r"""The data source of the trace"""

    parent_execution_id: OptionalNullable[str] = UNSET
    r"""The parent execution ID of the workflow execution"""

    run_id: OptionalNullable[str] = UNSET
    r"""The unique run identifier (database UUID)"""

    total_duration_ms: OptionalNullable[int] = UNSET
    r"""The total duration of the trace in milliseconds"""

    otel_trace_id: OptionalNullable[str] = UNSET
    r"""The ID of the trace"""

    otel_trace_data: OptionalNullable[TempoGetTraceResponse] = UNSET
    r"""The raw OpenTelemetry trace data"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "parent_execution_id",
                "run_id",
                "total_duration_ms",
                "otel_trace_id",
                "otel_trace_data",
            ]
        )
        nullable_fields = set(
            [
                "parent_execution_id",
                "run_id",
                "status",
                "end_time",
                "total_duration_ms",
                "result",
                "otel_trace_id",
                "otel_trace_data",
            ]
        )
        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
