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

from __future__ import annotations
from .types_filtercondition import TypesFilterCondition, TypesFilterConditionTypedDict
from .types_priceentitytype import TypesPriceEntityType
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


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


class TypesPriceFilterTypedDict(TypedDict):
    allow_expired_prices: NotRequired[bool]
    end_time: NotRequired[str]
    entity_ids: NotRequired[List[str]]
    entity_type: NotRequired[TypesPriceEntityType]
    expand: NotRequired[str]
    filters: NotRequired[List[TypesFilterConditionTypedDict]]
    r"""DSL filters"""
    limit: NotRequired[int]
    meter_ids: NotRequired[List[str]]
    offset: NotRequired[int]
    order: NotRequired[TypesPriceFilterOrder]
    parent_price_id: NotRequired[str]
    plan_ids: NotRequired[List[str]]
    r"""Price override filtering fields"""
    price_ids: NotRequired[List[str]]
    sort: NotRequired[str]
    start_date_lt: NotRequired[str]
    start_time: NotRequired[str]
    status: NotRequired[TypesStatus]
    subscription_id: NotRequired[str]


class TypesPriceFilter(BaseModel):
    allow_expired_prices: Optional[bool] = False

    end_time: Optional[str] = None

    entity_ids: Optional[List[str]] = None

    entity_type: Optional[TypesPriceEntityType] = None

    expand: Optional[str] = None

    filters: Optional[List[TypesFilterCondition]] = None
    r"""DSL filters"""

    limit: Optional[int] = None

    meter_ids: Optional[List[str]] = None

    offset: Optional[int] = None

    order: Optional[TypesPriceFilterOrder] = None

    parent_price_id: Optional[str] = None

    plan_ids: Optional[List[str]] = None
    r"""Price override filtering fields"""

    price_ids: Optional[List[str]] = None

    sort: Optional[str] = None

    start_date_lt: Optional[str] = None

    start_time: Optional[str] = None

    status: Optional[TypesStatus] = None

    subscription_id: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "allow_expired_prices",
                "end_time",
                "entity_ids",
                "entity_type",
                "expand",
                "filters",
                "limit",
                "meter_ids",
                "offset",
                "order",
                "parent_price_id",
                "plan_ids",
                "price_ids",
                "sort",
                "start_date_lt",
                "start_time",
                "status",
                "subscription_id",
            ]
        )
        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
