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

from __future__ import annotations
from .dto_createinvoicelineitemrequest import (
    DtoCreateInvoiceLineItemRequest,
    DtoCreateInvoiceLineItemRequestTypedDict,
)
from .dto_invoicecoupon import DtoInvoiceCoupon, DtoInvoiceCouponTypedDict
from .dto_invoicelineitemcoupon import (
    DtoInvoiceLineItemCoupon,
    DtoInvoiceLineItemCouponTypedDict,
)
from .dto_taxrateoverride import DtoTaxRateOverride, DtoTaxRateOverrideTypedDict
from .dto_taxrateresponse import DtoTaxRateResponse, DtoTaxRateResponseTypedDict
from .invoicebillingreason import InvoiceBillingReason
from .invoicestatus import InvoiceStatus
from .invoicetype import InvoiceType
from .paymentstatus import PaymentStatus
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoCreateInvoiceRequestTypedDict(TypedDict):
    amount_due: str
    r"""amount_due is the total amount that needs to be paid for this invoice"""
    currency: str
    r"""currency is the three-letter ISO currency code (e.g., USD, EUR) for the invoice"""
    customer_id: str
    r"""customer_id is the unique identifier of the customer this invoice belongs to"""
    subtotal: str
    r"""subtotal is the amount before taxes and discounts are applied"""
    total: str
    r"""total is the total amount of the invoice including taxes and discounts"""
    amount_paid: NotRequired[str]
    r"""amount_paid is the amount that has been paid towards this invoice"""
    billing_period: NotRequired[str]
    r"""billing_period is the period this invoice covers (e.g., \"monthly\", \"yearly\")"""
    billing_reason: NotRequired[InvoiceBillingReason]
    coupons: NotRequired[List[str]]
    r"""coupons"""
    description: NotRequired[str]
    r"""description is an optional text description of the invoice"""
    due_date: NotRequired[str]
    r"""due_date is the date by which payment is expected"""
    idempotency_key: NotRequired[str]
    r"""idempotency_key is an optional key used to prevent duplicate invoice creation"""
    invoice_coupons: NotRequired[List[DtoInvoiceCouponTypedDict]]
    r"""Invoice Coupons"""
    invoice_number: NotRequired[str]
    r"""invoice_number is an optional human-readable identifier for the invoice"""
    invoice_pdf_url: NotRequired[str]
    r"""invoice_pdf_url is the URL where customers can download the PDF version of this invoice"""
    invoice_status: NotRequired[InvoiceStatus]
    invoice_type: NotRequired[InvoiceType]
    line_item_coupons: NotRequired[List[DtoInvoiceLineItemCouponTypedDict]]
    r"""Invoice Line Item Coupons"""
    line_items: NotRequired[List[DtoCreateInvoiceLineItemRequestTypedDict]]
    r"""line_items contains the individual items that make up this invoice"""
    metadata: NotRequired[Dict[str, str]]
    payment_status: NotRequired[PaymentStatus]
    period_end: NotRequired[str]
    r"""period_end is the end date of the billing period"""
    period_start: NotRequired[str]
    r"""period_start is the start date of the billing period"""
    prepared_tax_rates: NotRequired[List[DtoTaxRateResponseTypedDict]]
    r"""prepared_tax_rates contains the tax rates pre-resolved by the caller (e.g., billing service)"""
    subscription_id: NotRequired[str]
    r"""subscription_id is the optional unique identifier of the subscription associated with this invoice"""
    tax_rate_overrides: NotRequired[List[DtoTaxRateOverrideTypedDict]]
    r"""tax_rate_overrides is the tax rate overrides to be applied to the invoice"""
    tax_rates: NotRequired[List[str]]
    r"""tax_rates"""
    total_prepaid_applied: NotRequired[str]
    r"""total_prepaid_applied is the total amount of prepaid applied to this invoice."""


class DtoCreateInvoiceRequest(BaseModel):
    amount_due: str
    r"""amount_due is the total amount that needs to be paid for this invoice"""

    currency: str
    r"""currency is the three-letter ISO currency code (e.g., USD, EUR) for the invoice"""

    customer_id: str
    r"""customer_id is the unique identifier of the customer this invoice belongs to"""

    subtotal: str
    r"""subtotal is the amount before taxes and discounts are applied"""

    total: str
    r"""total is the total amount of the invoice including taxes and discounts"""

    amount_paid: Optional[str] = None
    r"""amount_paid is the amount that has been paid towards this invoice"""

    billing_period: Optional[str] = None
    r"""billing_period is the period this invoice covers (e.g., \"monthly\", \"yearly\")"""

    billing_reason: Optional[InvoiceBillingReason] = None

    coupons: Optional[List[str]] = None
    r"""coupons"""

    description: Optional[str] = None
    r"""description is an optional text description of the invoice"""

    due_date: Optional[str] = None
    r"""due_date is the date by which payment is expected"""

    idempotency_key: Optional[str] = None
    r"""idempotency_key is an optional key used to prevent duplicate invoice creation"""

    invoice_coupons: Optional[List[DtoInvoiceCoupon]] = None
    r"""Invoice Coupons"""

    invoice_number: Optional[str] = None
    r"""invoice_number is an optional human-readable identifier for the invoice"""

    invoice_pdf_url: Optional[str] = None
    r"""invoice_pdf_url is the URL where customers can download the PDF version of this invoice"""

    invoice_status: Optional[InvoiceStatus] = None

    invoice_type: Optional[InvoiceType] = None

    line_item_coupons: Optional[List[DtoInvoiceLineItemCoupon]] = None
    r"""Invoice Line Item Coupons"""

    line_items: Optional[List[DtoCreateInvoiceLineItemRequest]] = None
    r"""line_items contains the individual items that make up this invoice"""

    metadata: Optional[Dict[str, str]] = None

    payment_status: Optional[PaymentStatus] = None

    period_end: Optional[str] = None
    r"""period_end is the end date of the billing period"""

    period_start: Optional[str] = None
    r"""period_start is the start date of the billing period"""

    prepared_tax_rates: Optional[List[DtoTaxRateResponse]] = None
    r"""prepared_tax_rates contains the tax rates pre-resolved by the caller (e.g., billing service)"""

    subscription_id: Optional[str] = None
    r"""subscription_id is the optional unique identifier of the subscription associated with this invoice"""

    tax_rate_overrides: Optional[List[DtoTaxRateOverride]] = None
    r"""tax_rate_overrides is the tax rate overrides to be applied to the invoice"""

    tax_rates: Optional[List[str]] = None
    r"""tax_rates"""

    total_prepaid_applied: Optional[str] = None
    r"""total_prepaid_applied is the total amount of prepaid applied to this invoice."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "amount_paid",
                "billing_period",
                "billing_reason",
                "coupons",
                "description",
                "due_date",
                "idempotency_key",
                "invoice_coupons",
                "invoice_number",
                "invoice_pdf_url",
                "invoice_status",
                "invoice_type",
                "line_item_coupons",
                "line_items",
                "metadata",
                "payment_status",
                "period_end",
                "period_start",
                "prepared_tax_rates",
                "subscription_id",
                "tax_rate_overrides",
                "tax_rates",
                "total_prepaid_applied",
            ]
        )
        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
