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

from __future__ import annotations
from .types_filtercondition import TypesFilterCondition, TypesFilterConditionTypedDict
from .types_invoicestatus import TypesInvoiceStatus
from .types_invoicetype import TypesInvoiceType
from .types_paymentstatus import TypesPaymentStatus
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


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


class TypesInvoiceFilterTypedDict(TypedDict):
    amount_due_gt: NotRequired[float]
    r"""amount_due_gt filters invoices with a total amount due greater than the specified value
    Useful for finding invoices above a certain threshold or identifying high-value invoices
    """
    amount_remaining_gt: NotRequired[float]
    r"""amount_remaining_gt filters invoices with an outstanding balance greater than the specified value
    Useful for finding invoices that still have significant unpaid amounts
    """
    customer_id: NotRequired[str]
    r"""customer_id filters invoices for a specific customer using FlexPrice's internal customer ID
    This is the ID returned by FlexPrice when creating or retrieving customers
    """
    end_time: NotRequired[str]
    expand: NotRequired[str]
    external_customer_id: NotRequired[str]
    r"""external_customer_id filters invoices for a customer using your system's customer identifier
    This is the ID you provided when creating the customer in FlexPrice
    """
    filters: NotRequired[List[TypesFilterConditionTypedDict]]
    invoice_ids: NotRequired[List[str]]
    r"""invoice_ids restricts results to invoices with the specified IDs
    Use this to retrieve specific invoices when you know their exact identifiers
    """
    invoice_status: NotRequired[List[TypesInvoiceStatus]]
    r"""invoice_status filters by the current state of invoices in their lifecycle
    Multiple statuses can be specified to include invoices in any of the listed states
    """
    invoice_type: NotRequired[TypesInvoiceType]
    limit: NotRequired[int]
    offset: NotRequired[int]
    order: NotRequired[TypesInvoiceFilterOrder]
    payment_status: NotRequired[List[TypesPaymentStatus]]
    r"""payment_status filters by the payment state of invoices
    Multiple statuses can be specified to include invoices with any of the listed payment states
    """
    period_end_gte: NotRequired[str]
    r"""period_end_gte filters invoices with period_end >= value"""
    period_end_lte: NotRequired[str]
    r"""period_end_lte filters invoices with period_end <= value"""
    period_start_gte: NotRequired[str]
    r"""period_start_gte filters invoices with period_start >= value"""
    period_start_lte: NotRequired[str]
    r"""period_start_lte filters invoices with period_start <= value"""
    skip_line_items: NotRequired[bool]
    r"""SkipLineItems if true, will not include line items in the response"""
    sort: NotRequired[List[TypesSortConditionTypedDict]]
    start_time: NotRequired[str]
    status: NotRequired[TypesStatus]
    subscription_id: NotRequired[str]
    r"""subscription_id filters invoices generated for a specific subscription
    Only returns invoices that were created as part of the specified subscription's billing
    """


class TypesInvoiceFilter(BaseModel):
    amount_due_gt: Optional[float] = None
    r"""amount_due_gt filters invoices with a total amount due greater than the specified value
    Useful for finding invoices above a certain threshold or identifying high-value invoices
    """

    amount_remaining_gt: Optional[float] = None
    r"""amount_remaining_gt filters invoices with an outstanding balance greater than the specified value
    Useful for finding invoices that still have significant unpaid amounts
    """

    customer_id: Optional[str] = None
    r"""customer_id filters invoices for a specific customer using FlexPrice's internal customer ID
    This is the ID returned by FlexPrice when creating or retrieving customers
    """

    end_time: Optional[str] = None

    expand: Optional[str] = None

    external_customer_id: Optional[str] = None
    r"""external_customer_id filters invoices for a customer using your system's customer identifier
    This is the ID you provided when creating the customer in FlexPrice
    """

    filters: Optional[List[TypesFilterCondition]] = None

    invoice_ids: Optional[List[str]] = None
    r"""invoice_ids restricts results to invoices with the specified IDs
    Use this to retrieve specific invoices when you know their exact identifiers
    """

    invoice_status: Optional[List[TypesInvoiceStatus]] = None
    r"""invoice_status filters by the current state of invoices in their lifecycle
    Multiple statuses can be specified to include invoices in any of the listed states
    """

    invoice_type: Optional[TypesInvoiceType] = None

    limit: Optional[int] = None

    offset: Optional[int] = None

    order: Optional[TypesInvoiceFilterOrder] = None

    payment_status: Optional[List[TypesPaymentStatus]] = None
    r"""payment_status filters by the payment state of invoices
    Multiple statuses can be specified to include invoices with any of the listed payment states
    """

    period_end_gte: Optional[str] = None
    r"""period_end_gte filters invoices with period_end >= value"""

    period_end_lte: Optional[str] = None
    r"""period_end_lte filters invoices with period_end <= value"""

    period_start_gte: Optional[str] = None
    r"""period_start_gte filters invoices with period_start >= value"""

    period_start_lte: Optional[str] = None
    r"""period_start_lte filters invoices with period_start <= value"""

    skip_line_items: Optional[bool] = None
    r"""SkipLineItems if true, will not include line items in the response"""

    sort: Optional[List[TypesSortCondition]] = None

    start_time: Optional[str] = None

    status: Optional[TypesStatus] = None

    subscription_id: Optional[str] = None
    r"""subscription_id filters invoices generated for a specific subscription
    Only returns invoices that were created as part of the specified subscription's billing
    """

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "amount_due_gt",
                "amount_remaining_gt",
                "customer_id",
                "end_time",
                "expand",
                "external_customer_id",
                "filters",
                "invoice_ids",
                "invoice_status",
                "invoice_type",
                "limit",
                "offset",
                "order",
                "payment_status",
                "period_end_gte",
                "period_end_lte",
                "period_start_gte",
                "period_start_lte",
                "skip_line_items",
                "sort",
                "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
