# This file was auto-generated by Fern from our API Definition.

from ..core.unchecked_base_model import UncheckedBaseModel
import typing
import pydantic
from .money import Money
from .payment_options import PaymentOptions
from .device_checkout_options import DeviceCheckoutOptions
from .action_cancel_reason import ActionCancelReason
from .checkout_options_payment_type import CheckoutOptionsPaymentType
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class TerminalCheckout(UncheckedBaseModel):
    """
    Represents a checkout processed by the Square Terminal.
    """

    id: typing.Optional[str] = pydantic.Field(default=None)
    """
    A unique ID for this `TerminalCheckout`.
    """

    amount_money: Money = pydantic.Field()
    """
    The amount of money (including the tax amount) that the Square Terminal device should try to collect.
    """

    reference_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    An optional user-defined reference ID that can be used to associate
    this `TerminalCheckout` to another entity in an external system. For example, an order
    ID generated by a third-party shopping cart. The ID is also associated with any payments
    used to complete the checkout.
    """

    note: typing.Optional[str] = pydantic.Field(default=None)
    """
    An optional note to associate with the checkout, as well as with any payments used to complete the checkout.
    Note: maximum 500 characters
    """

    order_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The reference to the Square order ID for the checkout request.
    """

    payment_options: typing.Optional[PaymentOptions] = pydantic.Field(default=None)
    """
    Payment-specific options for the checkout request.
    """

    device_options: DeviceCheckoutOptions = pydantic.Field()
    """
    Options to control the display and behavior of the Square Terminal device.
    """

    deadline_duration: typing.Optional[str] = pydantic.Field(default=None)
    """
    An RFC 3339 duration, after which the checkout is automatically canceled.
    A `TerminalCheckout` that is `PENDING` is automatically `CANCELED` and has a cancellation reason
    of `TIMED_OUT`.
    
    Default: 5 minutes from creation
    
    Maximum: 5 minutes
    """

    status: typing.Optional[str] = pydantic.Field(default=None)
    """
    The status of the `TerminalCheckout`.
    Options: `PENDING`, `IN_PROGRESS`, `CANCEL_REQUESTED`, `CANCELED`, `COMPLETED`
    """

    cancel_reason: typing.Optional[ActionCancelReason] = pydantic.Field(default=None)
    """
    The reason why `TerminalCheckout` is canceled. Present if the status is `CANCELED`.
    See [ActionCancelReason](#type-actioncancelreason) for possible values
    """

    payment_ids: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    A list of IDs for payments created by this `TerminalCheckout`.
    """

    created_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The time when the `TerminalCheckout` was created, as an RFC 3339 timestamp.
    """

    updated_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The time when the `TerminalCheckout` was last updated, as an RFC 3339 timestamp.
    """

    app_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The ID of the application that created the checkout.
    """

    location_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The location of the device where the `TerminalCheckout` was directed.
    """

    payment_type: typing.Optional[CheckoutOptionsPaymentType] = pydantic.Field(default=None)
    """
    The type of payment the terminal should attempt to capture from. Defaults to `CARD_PRESENT`.
    See [CheckoutOptionsPaymentType](#type-checkoutoptionspaymenttype) for possible values
    """

    team_member_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    An optional ID of the team member associated with creating the checkout.
    """

    customer_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    An optional ID of the customer associated with the checkout.
    """

    app_fee_money: typing.Optional[Money] = pydantic.Field(default=None)
    """
    The amount the developer is taking as a fee for facilitating the payment on behalf
    of the seller.
    
    The amount cannot be more than 90% of the total amount of the payment.
    
    The amount must be specified in the smallest denomination of the applicable currency (for example, US dollar amounts are specified in cents). For more information, see [Working with Monetary Amounts](https://developer.squareup.com/docs/build-basics/working-with-monetary-amounts).
    
    The fee currency code must match the currency associated with the seller that is accepting the payment. The application must be from a developer account in the same country and using the same currency code as the seller.
    
    For more information about the application fee scenario, see [Take Payments and Collect Fees](https://developer.squareup.com/docs/payments-api/take-payments-and-collect-fees).
    
    To set this field, PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS OAuth permission is required. For more information, see [Permissions](https://developer.squareup.com/docs/payments-api/take-payments-and-collect-fees#permissions).
    """

    statement_description_identifier: typing.Optional[str] = pydantic.Field(default=None)
    """
    Optional additional payment information to include on the customer's card statement as
    part of the statement description. This can be, for example, an invoice number, ticket number,
    or short description that uniquely identifies the purchase.
    """

    tip_money: typing.Optional[Money] = pydantic.Field(default=None)
    """
    The amount designated as a tip, in addition to `amount_money`. This may only be set for a
    checkout that has tipping disabled (`tip_settings.allow_tipping` is `false`).
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
