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

from __future__ import annotations
from .amountdecimal import AmountDecimal, AmountDecimalTypedDict
from .invoicelineitems import InvoiceLineItems, InvoiceLineItemsTypedDict
from .invoicepayment import InvoicePayment, InvoicePaymentTypedDict
from .invoicestatus import InvoiceStatus
from datetime import datetime
from moovio_sdk.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class InvoiceTypedDict(TypedDict):
    invoice_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)."""
    invoice_number: str
    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)."""
    customer_display_name: str
    r"""Display name of the customer account."""
    customer_email: str
    r"""Email address of the customer account."""
    partner_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)."""
    status: InvoiceStatus
    line_items: InvoiceLineItemsTypedDict
    r"""A collection of line items for an invoice."""
    subtotal_amount: AmountDecimalTypedDict
    tax_amount: AmountDecimalTypedDict
    total_amount: AmountDecimalTypedDict
    r"""Total amount of the invoice, sum of subTotalAmount and taxAmount"""
    pending_amount: AmountDecimalTypedDict
    r"""Total amount of pending transfers paid towards the invoice"""
    paid_amount: AmountDecimalTypedDict
    r"""Total amount of completed transfers paid towards the invoice"""
    refunded_amount: AmountDecimalTypedDict
    r"""Total amount of refunds initiated against transfers paid towards the invoice"""
    disputed_amount: AmountDecimalTypedDict
    r"""Total amount of disputes initiated against transfers paid towards the invoice"""
    created_on: datetime
    description: NotRequired[str]
    payment_link_code: NotRequired[str]
    invoice_payments: NotRequired[List[InvoicePaymentTypedDict]]
    r"""Payment made towards an invoice, will be either a transfer or an external payment."""
    invoice_date: NotRequired[datetime]
    due_date: NotRequired[datetime]
    sent_on: NotRequired[datetime]
    paid_on: NotRequired[datetime]
    canceled_on: NotRequired[datetime]
    disabled_on: NotRequired[datetime]


class Invoice(BaseModel):
    invoice_id: Annotated[str, pydantic.Field(alias="invoiceID")]
    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)."""

    invoice_number: Annotated[str, pydantic.Field(alias="invoiceNumber")]

    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)."""

    customer_display_name: Annotated[str, pydantic.Field(alias="customerDisplayName")]
    r"""Display name of the customer account."""

    customer_email: Annotated[str, pydantic.Field(alias="customerEmail")]
    r"""Email address of the customer account."""

    partner_account_id: Annotated[str, pydantic.Field(alias="partnerAccountID")]
    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)."""

    status: InvoiceStatus

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

    subtotal_amount: Annotated[AmountDecimal, pydantic.Field(alias="subtotalAmount")]

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

    total_amount: Annotated[AmountDecimal, pydantic.Field(alias="totalAmount")]
    r"""Total amount of the invoice, sum of subTotalAmount and taxAmount"""

    pending_amount: Annotated[AmountDecimal, pydantic.Field(alias="pendingAmount")]
    r"""Total amount of pending transfers paid towards the invoice"""

    paid_amount: Annotated[AmountDecimal, pydantic.Field(alias="paidAmount")]
    r"""Total amount of completed transfers paid towards the invoice"""

    refunded_amount: Annotated[AmountDecimal, pydantic.Field(alias="refundedAmount")]
    r"""Total amount of refunds initiated against transfers paid towards the invoice"""

    disputed_amount: Annotated[AmountDecimal, pydantic.Field(alias="disputedAmount")]
    r"""Total amount of disputes initiated against transfers paid towards the invoice"""

    created_on: Annotated[datetime, pydantic.Field(alias="createdOn")]

    description: Optional[str] = None

    payment_link_code: Annotated[
        Optional[str], pydantic.Field(alias="paymentLinkCode")
    ] = None

    invoice_payments: Annotated[
        Optional[List[InvoicePayment]], pydantic.Field(alias="invoicePayments")
    ] = None
    r"""Payment made towards an invoice, will be either a transfer or an external payment."""

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

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

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

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

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

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "description",
                "paymentLinkCode",
                "invoicePayments",
                "invoiceDate",
                "dueDate",
                "sentOn",
                "paidOn",
                "canceledOn",
                "disabledOn",
            ]
        )
        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:
    Invoice.model_rebuild()
except NameError:
    pass
