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

from __future__ import annotations
from .dto_invoicelineitempreview import (
    DtoInvoiceLineItemPreview,
    DtoInvoiceLineItemPreviewTypedDict,
)
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoInvoicePreviewTypedDict(TypedDict):
    currency: NotRequired[str]
    r"""currency is the currency for all amounts"""
    due_date: NotRequired[str]
    r"""due_date is when the invoice would be due"""
    line_items: NotRequired[List[DtoInvoiceLineItemPreviewTypedDict]]
    r"""line_items contains preview of line items"""
    subtotal: NotRequired[str]
    r"""subtotal is the subtotal amount before taxes"""
    tax_amount: NotRequired[str]
    r"""tax_amount is the total tax amount"""
    total: NotRequired[str]
    r"""total is the total amount including taxes"""


class DtoInvoicePreview(BaseModel):
    currency: Optional[str] = None
    r"""currency is the currency for all amounts"""

    due_date: Optional[str] = None
    r"""due_date is when the invoice would be due"""

    line_items: Optional[List[DtoInvoiceLineItemPreview]] = None
    r"""line_items contains preview of line items"""

    subtotal: Optional[str] = None
    r"""subtotal is the subtotal amount before taxes"""

    tax_amount: Optional[str] = None
    r"""tax_amount is the total tax amount"""

    total: Optional[str] = None
    r"""total is the total amount including taxes"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["currency", "due_date", "line_items", "subtotal", "tax_amount", "total"]
        )
        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
