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

from __future__ import annotations
from .streameventssepayload import StreamEventSsePayload, StreamEventSsePayloadTypedDict
from .workfloweventtype import WorkflowEventType
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from mistralai.client.utils import FieldMetadata, HeaderMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import Any, Dict, List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


Scope = Literal[
    "activity",
    "workflow",
    "*",
]


class GetStreamEventsV1WorkflowsEventsStreamGetRequestTypedDict(TypedDict):
    scope: NotRequired[Scope]
    activity_name: NotRequired[str]
    activity_id: NotRequired[str]
    workflow_name: NotRequired[str]
    workflow_exec_id: NotRequired[str]
    root_workflow_exec_id: NotRequired[str]
    parent_workflow_exec_id: NotRequired[str]
    stream: NotRequired[str]
    start_seq: NotRequired[int]
    metadata_filters: NotRequired[Nullable[Dict[str, Any]]]
    workflow_event_types: NotRequired[Nullable[List[WorkflowEventType]]]
    last_event_id: NotRequired[Nullable[str]]


class GetStreamEventsV1WorkflowsEventsStreamGetRequest(BaseModel):
    scope: Annotated[
        Optional[Scope],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = "*"

    activity_name: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = "*"

    activity_id: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = "*"

    workflow_name: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = "*"

    workflow_exec_id: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = "*"

    root_workflow_exec_id: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = "*"

    parent_workflow_exec_id: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = "*"

    stream: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = "*"

    start_seq: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 0

    metadata_filters: Annotated[
        OptionalNullable[Dict[str, Any]],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET

    workflow_event_types: Annotated[
        OptionalNullable[List[WorkflowEventType]],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET

    last_event_id: Annotated[
        OptionalNullable[str],
        pydantic.Field(alias="last-event-id"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "scope",
                "activity_name",
                "activity_id",
                "workflow_name",
                "workflow_exec_id",
                "root_workflow_exec_id",
                "parent_workflow_exec_id",
                "stream",
                "start_seq",
                "metadata_filters",
                "workflow_event_types",
                "last-event-id",
            ]
        )
        nullable_fields = set(
            ["metadata_filters", "workflow_event_types", "last-event-id"]
        )
        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


class GetStreamEventsV1WorkflowsEventsStreamGetResponseBodyTypedDict(TypedDict):
    r"""Stream of Server-Sent Events (SSE)"""

    event: NotRequired[str]
    data: NotRequired[StreamEventSsePayloadTypedDict]
    id: NotRequired[str]
    retry: NotRequired[int]


class GetStreamEventsV1WorkflowsEventsStreamGetResponseBody(BaseModel):
    r"""Stream of Server-Sent Events (SSE)"""

    event: Optional[str] = None

    data: Optional[StreamEventSsePayload] = None

    id: Optional[str] = None

    retry: Optional[int] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["event", "data", "id", "retry"])
        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))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
