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

from __future__ import annotations
from .types_billingcadence import TypesBillingCadence
from .types_billingperiod import TypesBillingPeriod
from .types_filtercondition import TypesFilterCondition, TypesFilterConditionTypedDict
from .types_sortcondition import TypesSortCondition, TypesSortConditionTypedDict
from .types_status import TypesStatus
from .types_subscriptionstatus import TypesSubscriptionStatus
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


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


class TypesSubscriptionFilterTypedDict(TypedDict):
    active_at: NotRequired[str]
    r"""ActiveAt filters subscriptions that are active at the given time"""
    billing_cadence: NotRequired[List[TypesBillingCadence]]
    r"""BillingCadence filters by billing cadence"""
    billing_period: NotRequired[List[TypesBillingPeriod]]
    r"""BillingPeriod filters by billing period"""
    customer_id: NotRequired[str]
    r"""CustomerID filters by customer ID"""
    end_time: NotRequired[str]
    expand: NotRequired[str]
    external_customer_id: NotRequired[str]
    r"""ExternalCustomerID filters by external customer ID"""
    filters: NotRequired[List[TypesFilterConditionTypedDict]]
    invoicing_customer_ids: NotRequired[List[str]]
    r"""InvoicingCustomerIDs filters by invoicing customer ID"""
    limit: NotRequired[int]
    offset: NotRequired[int]
    order: NotRequired[TypesSubscriptionFilterOrder]
    parent_subscription_ids: NotRequired[List[str]]
    r"""ParentSubscriptionIDs filters by parent subscription IDs"""
    plan_id: NotRequired[str]
    r"""PlanID filters by plan ID"""
    sort: NotRequired[List[TypesSortConditionTypedDict]]
    start_time: NotRequired[str]
    status: NotRequired[TypesStatus]
    subscription_ids: NotRequired[List[str]]
    subscription_status: NotRequired[List[TypesSubscriptionStatus]]
    r"""SubscriptionStatus filters by subscription status"""
    with_line_items: NotRequired[bool]
    r"""WithLineItems includes line items in the response"""


class TypesSubscriptionFilter(BaseModel):
    active_at: Optional[str] = None
    r"""ActiveAt filters subscriptions that are active at the given time"""

    billing_cadence: Optional[List[TypesBillingCadence]] = None
    r"""BillingCadence filters by billing cadence"""

    billing_period: Optional[List[TypesBillingPeriod]] = None
    r"""BillingPeriod filters by billing period"""

    customer_id: Optional[str] = None
    r"""CustomerID filters by customer ID"""

    end_time: Optional[str] = None

    expand: Optional[str] = None

    external_customer_id: Optional[str] = None
    r"""ExternalCustomerID filters by external customer ID"""

    filters: Optional[List[TypesFilterCondition]] = None

    invoicing_customer_ids: Optional[List[str]] = None
    r"""InvoicingCustomerIDs filters by invoicing customer ID"""

    limit: Optional[int] = None

    offset: Optional[int] = None

    order: Optional[TypesSubscriptionFilterOrder] = None

    parent_subscription_ids: Optional[List[str]] = None
    r"""ParentSubscriptionIDs filters by parent subscription IDs"""

    plan_id: Optional[str] = None
    r"""PlanID filters by plan ID"""

    sort: Optional[List[TypesSortCondition]] = None

    start_time: Optional[str] = None

    status: Optional[TypesStatus] = None

    subscription_ids: Optional[List[str]] = None

    subscription_status: Optional[List[TypesSubscriptionStatus]] = None
    r"""SubscriptionStatus filters by subscription status"""

    with_line_items: Optional[bool] = None
    r"""WithLineItems includes line items in the response"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "active_at",
                "billing_cadence",
                "billing_period",
                "customer_id",
                "end_time",
                "expand",
                "external_customer_id",
                "filters",
                "invoicing_customer_ids",
                "limit",
                "offset",
                "order",
                "parent_subscription_ids",
                "plan_id",
                "sort",
                "start_time",
                "status",
                "subscription_ids",
                "subscription_status",
                "with_line_items",
            ]
        )
        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
