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

from __future__ import annotations
from .amountdecimal import AmountDecimal, AmountDecimalTypedDict
from .invoiceexternalpayment import (
    InvoiceExternalPayment,
    InvoiceExternalPaymentTypedDict,
)
from .invoicepaymenttype import InvoicePaymentType
from .invoicetransferpayment import (
    InvoiceTransferPayment,
    InvoiceTransferPaymentTypedDict,
)
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 InvoicePaymentTypedDict(TypedDict):
    r"""Payment made towards an invoice, will be either a transfer or an external payment."""

    invoice_payment_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_payment_type: InvoicePaymentType
    amount: AmountDecimalTypedDict
    transfer: NotRequired[InvoiceTransferPaymentTypedDict]
    external: NotRequired[InvoiceExternalPaymentTypedDict]


class InvoicePayment(BaseModel):
    r"""Payment made towards an invoice, will be either a transfer or an external payment."""

    invoice_payment_id: Annotated[str, pydantic.Field(alias="invoicePaymentID")]
    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_payment_type: Annotated[
        InvoicePaymentType, pydantic.Field(alias="invoicePaymentType")
    ]

    amount: AmountDecimal

    transfer: Optional[InvoiceTransferPayment] = None

    external: Optional[InvoiceExternalPayment] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["transfer", "external"])
        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:
    InvoicePayment.model_rebuild()
except NameError:
    pass
