"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .types_filtercondition import TypesFilterCondition, TypesFilterConditionTypedDict
from .types_sortcondition import TypesSortCondition, TypesSortConditionTypedDict
from .types_status import TypesStatus
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Literal, Optional
from typing_extensions import NotRequired, TypedDict


TypesWorkflowExecutionFilterOrder = Literal[
    "asc",
    "desc",
]


class TypesWorkflowExecutionFilterTypedDict(TypedDict):
    end_time: NotRequired[str]
    entity: NotRequired[str]
    r"""e.g. plan, invoice, subscription"""
    entity_id: NotRequired[str]
    r"""e.g. plan_01ABC123"""
    expand: NotRequired[str]
    filters: NotRequired[List[TypesFilterConditionTypedDict]]
    r"""filters allows complex filtering based on multiple fields (same as FeatureFilter)"""
    limit: NotRequired[int]
    offset: NotRequired[int]
    order: NotRequired[TypesWorkflowExecutionFilterOrder]
    sort: NotRequired[List[TypesSortConditionTypedDict]]
    start_time: NotRequired[str]
    status: NotRequired[TypesStatus]
    task_queue: NotRequired[str]
    workflow_id: NotRequired[str]
    r"""Workflow-specific filters"""
    workflow_status: NotRequired[str]
    r"""e.g. Running, Completed, Failed"""
    workflow_type: NotRequired[str]


class TypesWorkflowExecutionFilter(BaseModel):
    end_time: Optional[str] = None

    entity: Optional[str] = None
    r"""e.g. plan, invoice, subscription"""

    entity_id: Optional[str] = None
    r"""e.g. plan_01ABC123"""

    expand: Optional[str] = None

    filters: Optional[List[TypesFilterCondition]] = None
    r"""filters allows complex filtering based on multiple fields (same as FeatureFilter)"""

    limit: Optional[int] = None

    offset: Optional[int] = None

    order: Optional[TypesWorkflowExecutionFilterOrder] = None

    sort: Optional[List[TypesSortCondition]] = None

    start_time: Optional[str] = None

    status: Optional[TypesStatus] = None

    task_queue: Optional[str] = None

    workflow_id: Optional[str] = None
    r"""Workflow-specific filters"""

    workflow_status: Optional[str] = None
    r"""e.g. Running, Completed, Failed"""

    workflow_type: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "end_time",
                "entity",
                "entity_id",
                "expand",
                "filters",
                "limit",
                "offset",
                "order",
                "sort",
                "start_time",
                "status",
                "task_queue",
                "workflow_id",
                "workflow_status",
                "workflow_type",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

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

        return m
