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

from __future__ import annotations
from .workflowexecutionlistresponse import (
    WorkflowExecutionListResponse,
    WorkflowExecutionListResponseTypedDict,
)
from .workflowexecutionstatus import WorkflowExecutionStatus
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from mistralai.client.utils import FieldMetadata, QueryParamMetadata
from pydantic import model_serializer
from typing import Awaitable, Callable, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


ListRunsV1WorkflowsRunsGetStatusTypedDict = TypeAliasType(
    "ListRunsV1WorkflowsRunsGetStatusTypedDict",
    Union[WorkflowExecutionStatus, List[WorkflowExecutionStatus]],
)
r"""Filter by workflow status"""


ListRunsV1WorkflowsRunsGetStatus = TypeAliasType(
    "ListRunsV1WorkflowsRunsGetStatus",
    Union[WorkflowExecutionStatus, List[WorkflowExecutionStatus]],
)
r"""Filter by workflow status"""


class ListRunsV1WorkflowsRunsGetRequestTypedDict(TypedDict):
    workflow_identifier: NotRequired[Nullable[str]]
    r"""Filter by workflow name or id"""
    search: NotRequired[Nullable[str]]
    r"""Search by workflow name, display name or id"""
    status: NotRequired[Nullable[ListRunsV1WorkflowsRunsGetStatusTypedDict]]
    r"""Filter by workflow status"""
    page_size: NotRequired[int]
    r"""Number of items per page"""
    next_page_token: NotRequired[Nullable[str]]
    r"""Token for the next page of results"""


class ListRunsV1WorkflowsRunsGetRequest(BaseModel):
    workflow_identifier: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Filter by workflow name or id"""

    search: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Search by workflow name, display name or id"""

    status: Annotated[
        OptionalNullable[ListRunsV1WorkflowsRunsGetStatus],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Filter by workflow status"""

    page_size: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 50
    r"""Number of items per page"""

    next_page_token: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Token for the next page of results"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["workflow_identifier", "search", "status", "page_size", "next_page_token"]
        )
        nullable_fields = set(
            ["workflow_identifier", "search", "status", "next_page_token"]
        )
        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 ListRunsV1WorkflowsRunsGetResponseTypedDict(TypedDict):
    result: WorkflowExecutionListResponseTypedDict


class ListRunsV1WorkflowsRunsGetResponse(BaseModel):
    next: Union[
        Callable[[], Optional[ListRunsV1WorkflowsRunsGetResponse]],
        Callable[[], Awaitable[Optional[ListRunsV1WorkflowsRunsGetResponse]]],
    ]

    result: WorkflowExecutionListResponse
