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

from __future__ import annotations
from .invoice import Invoice, InvoiceTypedDict
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
from paygentic_sdk.utils import FieldMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


NextActionAt = Literal["ready",]
r"""Filter for invoices ready for processing (platform only)"""


ListInvoicesStatus = Literal[
    "ACTIVE",
    "CLOSING",
    "CLOSED",
    "CALCULATING",
    "DRAFT",
    "ISSUED",
    "PAYMENT_FAILED",
    "PAID",
    "CANCELLED",
    "WRITTEN_OFF",
    "FAILED",
]
r"""Filter invoices by status"""


class ListInvoicesRequestTypedDict(TypedDict):
    limit: NotRequired[int]
    r"""Maximum number of invoices to return"""
    next_action_at: NotRequired[NextActionAt]
    r"""Filter for invoices ready for processing (platform only)"""
    status: NotRequired[ListInvoicesStatus]
    r"""Filter invoices by status"""
    subscription_id: NotRequired[str]
    r"""Filter invoices by subscription ID"""


class ListInvoicesRequest(BaseModel):
    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 10
    r"""Maximum number of invoices to return"""

    next_action_at: Annotated[
        Optional[NextActionAt],
        pydantic.Field(alias="nextActionAt"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter for invoices ready for processing (platform only)"""

    status: Annotated[
        Optional[ListInvoicesStatus],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter invoices by status"""

    subscription_id: Annotated[
        Optional[str],
        pydantic.Field(alias="subscriptionId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter invoices by subscription ID"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["limit", "nextActionAt", "status", "subscriptionId"])
        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


ListInvoicesObject = Literal["list",]


class ListInvoicesResponseTypedDict(TypedDict):
    r"""List of invoices"""

    object: ListInvoicesObject
    data: List[InvoiceTypedDict]


class ListInvoicesResponse(BaseModel):
    r"""List of invoices"""

    object: ListInvoicesObject

    data: List[Invoice]
