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

from __future__ import annotations
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from flexprice_py.utils import FieldMetadata, QueryParamMetadata
from pydantic import model_serializer
from typing import Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


EntityType = Literal[
    "EVENTS",
    "PRICES",
    "CUSTOMERS",
    "FEATURES",
]


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


ListTasksStatus = Literal[
    "published",
    "deleted",
    "archived",
]


TaskStatus = Literal[
    "PENDING",
    "PROCESSING",
    "COMPLETED",
    "FAILED",
]


TaskType = Literal[
    "IMPORT",
    "EXPORT",
]


class ListTasksRequestTypedDict(TypedDict):
    created_by: NotRequired[str]
    end_time: NotRequired[str]
    entity_type: NotRequired[EntityType]
    expand: NotRequired[str]
    limit: NotRequired[int]
    offset: NotRequired[int]
    order: NotRequired[ListTasksOrder]
    scheduled_task_id: NotRequired[str]
    sort: NotRequired[str]
    start_time: NotRequired[str]
    status: NotRequired[ListTasksStatus]
    task_status: NotRequired[TaskStatus]
    task_type: NotRequired[TaskType]


class ListTasksRequest(BaseModel):
    created_by: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

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

    entity_type: Annotated[
        Optional[EntityType],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

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

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

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

    order: Annotated[
        Optional[ListTasksOrder],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

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

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

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

    status: Annotated[
        Optional[ListTasksStatus],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    task_status: Annotated[
        Optional[TaskStatus],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    task_type: Annotated[
        Optional[TaskType],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "created_by",
                "end_time",
                "entity_type",
                "expand",
                "limit",
                "offset",
                "order",
                "scheduled_task_id",
                "sort",
                "start_time",
                "status",
                "task_status",
                "task_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
