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

from __future__ import annotations
from datetime import datetime
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from mistralai.client.utils import FieldMetadata, PathParamMetadata, QueryParamMetadata
from pydantic import model_serializer
from typing_extensions import Annotated, NotRequired, TypedDict


class GetWorkflowMetricsV1WorkflowsWorkflowNameMetricsGetRequestTypedDict(TypedDict):
    workflow_name: str
    start_time: NotRequired[Nullable[datetime]]
    r"""Filter workflows started after this time (ISO 8601)"""
    end_time: NotRequired[Nullable[datetime]]
    r"""Filter workflows started before this time (ISO 8601)"""


class GetWorkflowMetricsV1WorkflowsWorkflowNameMetricsGetRequest(BaseModel):
    workflow_name: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]

    start_time: Annotated[
        OptionalNullable[datetime],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Filter workflows started after this time (ISO 8601)"""

    end_time: Annotated[
        OptionalNullable[datetime],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Filter workflows started before this time (ISO 8601)"""

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