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

from __future__ import annotations
from .types_entitlemententitytype import TypesEntitlementEntityType
from .types_featuretype import TypesFeatureType
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


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


class TypesEntitlementFilterTypedDict(TypedDict):
    end_time: NotRequired[str]
    entity_ids: NotRequired[List[str]]
    entity_type: NotRequired[TypesEntitlementEntityType]
    expand: NotRequired[str]
    feature_ids: NotRequired[List[str]]
    feature_type: NotRequired[TypesFeatureType]
    filters: NotRequired[List[TypesFilterConditionTypedDict]]
    r"""Specific filters for entitlements"""
    is_enabled: NotRequired[bool]
    limit: NotRequired[int]
    offset: NotRequired[int]
    order: NotRequired[TypesEntitlementFilterOrder]
    plan_ids: NotRequired[List[str]]
    sort: NotRequired[List[TypesSortConditionTypedDict]]
    start_time: NotRequired[str]
    status: NotRequired[TypesStatus]


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

    entity_ids: Optional[List[str]] = None

    entity_type: Optional[TypesEntitlementEntityType] = None

    expand: Optional[str] = None

    feature_ids: Optional[List[str]] = None

    feature_type: Optional[TypesFeatureType] = None

    filters: Optional[List[TypesFilterCondition]] = None
    r"""Specific filters for entitlements"""

    is_enabled: Optional[bool] = None

    limit: Optional[int] = None

    offset: Optional[int] = None

    order: Optional[TypesEntitlementFilterOrder] = None

    plan_ids: Optional[List[str]] = None

    sort: Optional[List[TypesSortCondition]] = None

    start_time: Optional[str] = None

    status: Optional[TypesStatus] = None

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