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

from __future__ import annotations
from .amount import Amount, AmountTypedDict
from .createpaymentlinklineitems import (
    CreatePaymentLinkLineItems,
    CreatePaymentLinkLineItemsTypedDict,
)
from .paymentlinkcustomeroptions import (
    PaymentLinkCustomerOptions,
    PaymentLinkCustomerOptionsTypedDict,
)
from .paymentlinkdisplayoptions import (
    PaymentLinkDisplayOptions,
    PaymentLinkDisplayOptionsTypedDict,
)
from .paymentlinkpaymentdetails import (
    PaymentLinkPaymentDetails,
    PaymentLinkPaymentDetailsTypedDict,
)
from .paymentlinkpayoutdetails import (
    PaymentLinkPayoutDetails,
    PaymentLinkPayoutDetailsTypedDict,
)
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 CreatePaymentLinkTypedDict(TypedDict):
    r"""Request to create a new payment link.

    A payment link must include either `payment` or `payout` details, but not both. For payout payment links,
    `maxUses` will automatically be set to 1, as these are intended for a one-time disbursement
    to a specific recipient.

    """

    partner_account_id: str
    r"""The partner's Moov account ID."""
    merchant_payment_method_id: str
    r"""The merchant's preferred payment method ID. Must be a wallet payment method."""
    amount: AmountTypedDict
    display: PaymentLinkDisplayOptionsTypedDict
    r"""Customizable display options for a payment link."""
    sales_tax_amount: NotRequired[AmountTypedDict]
    max_uses: NotRequired[int]
    r"""An optional limit on the number of times this payment link can be used.

    **For payouts, `maxUses` is always 1.**
    """
    expires_on: NotRequired[datetime]
    r"""An optional expiration date for this payment link."""
    customer: NotRequired[PaymentLinkCustomerOptionsTypedDict]
    payment: NotRequired[PaymentLinkPaymentDetailsTypedDict]
    r"""Options for payment links used to collect payment."""
    payout: NotRequired[PaymentLinkPayoutDetailsTypedDict]
    line_items: NotRequired[CreatePaymentLinkLineItemsTypedDict]
    r"""An optional collection of line items for a payment link.
    When line items are provided, their total plus sales tax must equal the payment link amount.
    """


class CreatePaymentLink(BaseModel):
    r"""Request to create a new payment link.

    A payment link must include either `payment` or `payout` details, but not both. For payout payment links,
    `maxUses` will automatically be set to 1, as these are intended for a one-time disbursement
    to a specific recipient.

    """

    partner_account_id: Annotated[str, pydantic.Field(alias="partnerAccountID")]
    r"""The partner's Moov account ID."""

    merchant_payment_method_id: Annotated[
        str, pydantic.Field(alias="merchantPaymentMethodID")
    ]
    r"""The merchant's preferred payment method ID. Must be a wallet payment method."""

    amount: Amount

    display: PaymentLinkDisplayOptions
    r"""Customizable display options for a payment link."""

    sales_tax_amount: Annotated[
        Optional[Amount], pydantic.Field(alias="salesTaxAmount")
    ] = None

    max_uses: Annotated[Optional[int], pydantic.Field(alias="maxUses")] = None
    r"""An optional limit on the number of times this payment link can be used.

    **For payouts, `maxUses` is always 1.**
    """

    expires_on: Annotated[Optional[datetime], pydantic.Field(alias="expiresOn")] = None
    r"""An optional expiration date for this payment link."""

    customer: Optional[PaymentLinkCustomerOptions] = None

    payment: Optional[PaymentLinkPaymentDetails] = None
    r"""Options for payment links used to collect payment."""

    payout: Optional[PaymentLinkPayoutDetails] = None

    line_items: Annotated[
        Optional[CreatePaymentLinkLineItems], pydantic.Field(alias="lineItems")
    ] = None
    r"""An optional collection of line items for a payment link.
    When line items are provided, their total plus sales tax must equal the payment link amount.
    """

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "salesTaxAmount",
                "maxUses",
                "expiresOn",
                "customer",
                "payment",
                "payout",
                "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:
    CreatePaymentLink.model_rebuild()
except NameError:
    pass
