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

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


ListPriceUnitsOrder = Literal[
    "asc",
    "desc",
]
r"""Sort order"""


class ListPriceUnitsRequestTypedDict(TypedDict):
    status: NotRequired[str]
    r"""Filter by status"""
    limit: NotRequired[int]
    r"""Limit number of results"""
    offset: NotRequired[int]
    r"""Offset for pagination"""
    sort: NotRequired[str]
    r"""Sort field"""
    order: NotRequired[ListPriceUnitsOrder]
    r"""Sort order"""


class ListPriceUnitsRequest(BaseModel):
    status: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter by status"""

    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 50
    r"""Limit number of results"""

    offset: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 0
    r"""Offset for pagination"""

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

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["status", "limit", "offset", "sort", "order"])
        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
