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

from __future__ import annotations
from .amount import Amount, AmountTypedDict
from .createscheduledtransferlineitems import (
    CreateScheduledTransferLineItems,
    CreateScheduledTransferLineItemsTypedDict,
)
from .schedulepaymentmethod import SchedulePaymentMethod, SchedulePaymentMethodTypedDict
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 CreateRunTransferTypedDict(TypedDict):
    r"""Defines the attributes of a transfer."""

    amount: AmountTypedDict
    destination: SchedulePaymentMethodTypedDict
    partner_account_id: str
    source: SchedulePaymentMethodTypedDict
    description: str
    r"""Simple description to place on the transfer."""
    sales_tax_amount: NotRequired[AmountTypedDict]
    r"""Optional sales tax amount. This amount is included in the total transfer amount."""
    line_items: NotRequired[CreateScheduledTransferLineItemsTypedDict]
    r"""An optional collection of line items for a scheduled transfer.
    When line items are provided their total must equal `amount` minus `salesTaxAmount`.
    """


class CreateRunTransfer(BaseModel):
    r"""Defines the attributes of a transfer."""

    amount: Amount

    destination: SchedulePaymentMethod

    partner_account_id: Annotated[str, pydantic.Field(alias="partnerAccountID")]

    source: SchedulePaymentMethod

    description: str
    r"""Simple description to place on the transfer."""

    sales_tax_amount: Annotated[
        Optional[Amount], pydantic.Field(alias="salesTaxAmount")
    ] = None
    r"""Optional sales tax amount. This amount is included in the total transfer amount."""

    line_items: Annotated[
        Optional[CreateScheduledTransferLineItems], pydantic.Field(alias="lineItems")
    ] = None
    r"""An optional collection of line items for a scheduled transfer.
    When line items are provided their total must equal `amount` minus `salesTaxAmount`.
    """

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