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

from ..core.unchecked_base_model import UncheckedBaseModel
import typing
import pydantic
from .action_cancel_reason import ActionCancelReason
from .terminal_action_action_type import TerminalActionActionType
from .qr_code_options import QrCodeOptions
from .save_card_options import SaveCardOptions
from .signature_options import SignatureOptions
from .confirmation_options import ConfirmationOptions
from .receipt_options import ReceiptOptions
from .data_collection_options import DataCollectionOptions
from .select_options import SelectOptions
from .device_metadata import DeviceMetadata
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class TerminalAction(UncheckedBaseModel):
    """
    Represents an action processed by the Square Terminal.
    """

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

    device_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The unique Id of the device intended for this `TerminalAction`.
    The Id can be retrieved from /v2/devices api.
    """

    deadline_duration: typing.Optional[str] = pydantic.Field(default=None)
    """
    The duration as an RFC 3339 duration, after which the action will be automatically canceled.
    TerminalActions that are `PENDING` will be automatically `CANCELED` and have 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 `TerminalAction`.
    Options: `PENDING`, `IN_PROGRESS`, `CANCEL_REQUESTED`, `CANCELED`, `COMPLETED`
    """

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

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

    updated_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The time when the `TerminalAction` 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 action.
    """

    location_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The location id the action is attached to, if a link can be made.
    """

    type: typing.Optional[TerminalActionActionType] = pydantic.Field(default=None)
    """
    Represents the type of the action.
    See [ActionType](#type-actiontype) for possible values
    """

    qr_code_options: typing.Optional[QrCodeOptions] = pydantic.Field(default=None)
    """
    Describes configuration for the QR code action. Requires `QR_CODE` type.
    """

    save_card_options: typing.Optional[SaveCardOptions] = pydantic.Field(default=None)
    """
    Describes configuration for the save-card action. Requires `SAVE_CARD` type.
    """

    signature_options: typing.Optional[SignatureOptions] = pydantic.Field(default=None)
    """
    Describes configuration for the signature capture action. Requires `SIGNATURE` type.
    """

    confirmation_options: typing.Optional[ConfirmationOptions] = pydantic.Field(default=None)
    """
    Describes configuration for the confirmation action. Requires `CONFIRMATION` type.
    """

    receipt_options: typing.Optional[ReceiptOptions] = pydantic.Field(default=None)
    """
    Describes configuration for the receipt action. Requires `RECEIPT` type.
    """

    data_collection_options: typing.Optional[DataCollectionOptions] = pydantic.Field(default=None)
    """
    Describes configuration for the data collection action. Requires `DATA_COLLECTION` type.
    """

    select_options: typing.Optional[SelectOptions] = pydantic.Field(default=None)
    """
    Describes configuration for the select action. Requires `SELECT` type.
    """

    device_metadata: typing.Optional[DeviceMetadata] = pydantic.Field(default=None)
    """
    Details about the Terminal that received the action request (such as battery level,
    operating system version, and network connection settings).
    
    Only available for `PING` action type.
    """

    await_next_action: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Indicates the action will be linked to another action and requires a waiting dialog to be
    displayed instead of returning to the idle screen on completion of the action.
    
    Only supported on SIGNATURE, CONFIRMATION, DATA_COLLECTION, and SELECT types.
    """

    await_next_action_duration: typing.Optional[str] = pydantic.Field(default=None)
    """
    The timeout duration of the waiting dialog as an RFC 3339 duration, after which the
    waiting dialog will no longer be displayed and the Terminal will return to the idle screen.
    
    Default: 5 minutes from when the waiting dialog is displayed
    
    Maximum: 5 minutes
    """

    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
