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

from __future__ import annotations
from .filtercondition import FilterCondition, FilterConditionTypedDict
from .invoicestatus import InvoiceStatus
from .invoicetype import InvoiceType
from .paymentstatus import PaymentStatus
from .sortcondition import SortCondition, SortConditionTypedDict
from .status import Status
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Literal, Optional
from typing_extensions import NotRequired, TypedDict


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


class InvoiceFilterTypedDict(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[FilterConditionTypedDict]]
    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[InvoiceStatus]]
    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[InvoiceType]
    limit: NotRequired[int]
    offset: NotRequired[int]
    order: NotRequired[InvoiceFilterOrder]
    payment_status: NotRequired[List[PaymentStatus]]
    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[SortConditionTypedDict]]
    start_time: NotRequired[str]
    status: NotRequired[Status]
    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 InvoiceFilter(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[FilterCondition]] = 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[InvoiceStatus]] = 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[InvoiceType] = None

    limit: Optional[int] = None

    offset: Optional[int] = None

    order: Optional[InvoiceFilterOrder] = None

    payment_status: Optional[List[PaymentStatus]] = 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[SortCondition]] = None

    start_time: Optional[str] = None

    status: Optional[Status] = 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, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
