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

from __future__ import annotations
from .amountdecimal import AmountDecimal, AmountDecimalTypedDict
from .createinvoicelineitems import (
    CreateInvoiceLineItems,
    CreateInvoiceLineItemsTypedDict,
)
from datetime import datetime
from moovio_sdk.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class CreateInvoiceTypedDict(TypedDict):
    customer_account_id: str
    r"""A unique identifier for a Moov resource. Supports UUID format (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) or typed format with base32-encoded UUID and type suffix (e.g., kuoaydiojf7uszaokc2ggnaaaa_xfer)."""
    line_items: CreateInvoiceLineItemsTypedDict
    r"""A collection of line items for an invoice."""
    description: NotRequired[str]
    invoice_date: NotRequired[datetime]
    due_date: NotRequired[datetime]
    tax_amount: NotRequired[AmountDecimalTypedDict]


class CreateInvoice(BaseModel):
    customer_account_id: Annotated[str, pydantic.Field(alias="customerAccountID")]
    r"""A unique identifier for a Moov resource. Supports UUID format (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) or typed format with base32-encoded UUID and type suffix (e.g., kuoaydiojf7uszaokc2ggnaaaa_xfer)."""

    line_items: Annotated[CreateInvoiceLineItems, pydantic.Field(alias="lineItems")]
    r"""A collection of line items for an invoice."""

    description: Optional[str] = None

    invoice_date: Annotated[Optional[datetime], pydantic.Field(alias="invoiceDate")] = (
        None
    )

    due_date: Annotated[Optional[datetime], pydantic.Field(alias="dueDate")] = None

    tax_amount: Annotated[
        Optional[AmountDecimal], pydantic.Field(alias="taxAmount")
    ] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["description", "invoiceDate", "dueDate", "taxAmount"])
        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


try:
    CreateInvoice.model_rebuild()
except NameError:
    pass
