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

from ..core.unchecked_base_model import UncheckedBaseModel
import typing
import pydantic
from .gift_card_activity_type import GiftCardActivityType
from .money import Money
from .gift_card_activity_load import GiftCardActivityLoad
from .gift_card_activity_activate import GiftCardActivityActivate
from .gift_card_activity_redeem import GiftCardActivityRedeem
from .gift_card_activity_clear_balance import GiftCardActivityClearBalance
from .gift_card_activity_deactivate import GiftCardActivityDeactivate
from .gift_card_activity_adjust_increment import GiftCardActivityAdjustIncrement
from .gift_card_activity_adjust_decrement import GiftCardActivityAdjustDecrement
from .gift_card_activity_refund import GiftCardActivityRefund
from .gift_card_activity_unlinked_activity_refund import GiftCardActivityUnlinkedActivityRefund
from .gift_card_activity_import import GiftCardActivityImport
from .gift_card_activity_block import GiftCardActivityBlock
from .gift_card_activity_unblock import GiftCardActivityUnblock
from .gift_card_activity_import_reversal import GiftCardActivityImportReversal
from .gift_card_activity_transfer_balance_to import GiftCardActivityTransferBalanceTo
from .gift_card_activity_transfer_balance_from import GiftCardActivityTransferBalanceFrom
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class GiftCardActivity(UncheckedBaseModel):
    """
    Represents an action performed on a [gift card](entity:GiftCard) that affects its state or balance.
    A gift card activity contains information about a specific activity type. For example, a `REDEEM` activity
    includes a `redeem_activity_details` field that contains information about the redemption.
    """

    id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The Square-assigned ID of the gift card activity.
    """

    type: GiftCardActivityType = pydantic.Field()
    """
    The type of gift card activity.
    See [Type](#type-type) for possible values
    """

    location_id: str = pydantic.Field()
    """
    The ID of the [business location](entity:Location) where the activity occurred.
    """

    created_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The timestamp when the gift card activity was created, in RFC 3339 format.
    """

    gift_card_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The gift card ID. When creating a gift card activity, `gift_card_id` is not required if 
    `gift_card_gan` is specified.
    """

    gift_card_gan: typing.Optional[str] = pydantic.Field(default=None)
    """
    The gift card account number (GAN). When creating a gift card activity, `gift_card_gan` 
    is not required if `gift_card_id` is specified.
    """

    gift_card_balance_money: typing.Optional[Money] = pydantic.Field(default=None)
    """
    The final balance on the gift card after the action is completed.
    """

    load_activity_details: typing.Optional[GiftCardActivityLoad] = pydantic.Field(default=None)
    """
    Additional details about a `LOAD` activity, which is used to reload money onto a gift card.
    """

    activate_activity_details: typing.Optional[GiftCardActivityActivate] = pydantic.Field(default=None)
    """
    Additional details about an `ACTIVATE` activity, which is used to activate a gift card with 
    an initial balance.
    """

    redeem_activity_details: typing.Optional[GiftCardActivityRedeem] = pydantic.Field(default=None)
    """
    Additional details about a `REDEEM` activity, which is used to redeem a gift card for a purchase.
    
    For applications that process payments using the Square Payments API, Square creates a `REDEEM` activity that 
    updates the gift card balance after the corresponding [CreatePayment](api-endpoint:Payments-CreatePayment) 
    request is completed. Applications that use a custom payment processing system must call 
    [CreateGiftCardActivity](api-endpoint:GiftCardActivities-CreateGiftCardActivity) to create the `REDEEM` activity.
    """

    clear_balance_activity_details: typing.Optional[GiftCardActivityClearBalance] = pydantic.Field(default=None)
    """
    Additional details about a `CLEAR_BALANCE` activity, which is used to set the balance of a gift card to zero.
    """

    deactivate_activity_details: typing.Optional[GiftCardActivityDeactivate] = pydantic.Field(default=None)
    """
    Additional details about a `DEACTIVATE` activity, which is used to deactivate a gift card.
    """

    adjust_increment_activity_details: typing.Optional[GiftCardActivityAdjustIncrement] = pydantic.Field(default=None)
    """
    Additional details about an `ADJUST_INCREMENT` activity, which is used to add money to a gift card 
    outside of a typical `ACTIVATE`, `LOAD`, or `REFUND` activity flow.
    """

    adjust_decrement_activity_details: typing.Optional[GiftCardActivityAdjustDecrement] = pydantic.Field(default=None)
    """
    Additional details about an `ADJUST_DECREMENT` activity, which is used to deduct money from a gift 
    card outside of a typical `REDEEM` activity flow.
    """

    refund_activity_details: typing.Optional[GiftCardActivityRefund] = pydantic.Field(default=None)
    """
    Additional details about a `REFUND` activity, which is used to add money to a gift card when 
    refunding a payment.
    
    For applications that refund payments to a gift card using the Square Refunds API, Square automatically
    creates a `REFUND` activity that updates the gift card balance after a [RefundPayment](api-endpoint:Refunds-RefundPayment)
    request is completed. Applications that use a custom processing system must call
    [CreateGiftCardActivity](api-endpoint:GiftCardActivities-CreateGiftCardActivity) to create the `REFUND` activity.
    """

    unlinked_activity_refund_activity_details: typing.Optional[GiftCardActivityUnlinkedActivityRefund] = pydantic.Field(
        default=None
    )
    """
    Additional details about an `UNLINKED_ACTIVITY_REFUND` activity. This activity is used to add money 
    to a gift card when refunding a payment that was processed using a custom payment processing system
    and not linked to the gift card.
    """

    import_activity_details: typing.Optional[GiftCardActivityImport] = pydantic.Field(default=None)
    """
    Additional details about an `IMPORT` activity, which Square uses to import a third-party 
    gift card with a balance.
    """

    block_activity_details: typing.Optional[GiftCardActivityBlock] = pydantic.Field(default=None)
    """
    Additional details about a `BLOCK` activity, which Square uses to temporarily block a gift card.
    """

    unblock_activity_details: typing.Optional[GiftCardActivityUnblock] = pydantic.Field(default=None)
    """
    Additional details about an `UNBLOCK` activity, which Square uses to unblock a gift card.
    """

    import_reversal_activity_details: typing.Optional[GiftCardActivityImportReversal] = pydantic.Field(default=None)
    """
    Additional details about an `IMPORT_REVERSAL` activity, which Square uses to reverse the 
    import of a third-party gift card.
    """

    transfer_balance_to_activity_details: typing.Optional[GiftCardActivityTransferBalanceTo] = pydantic.Field(
        default=None
    )
    """
    Additional details about a `TRANSFER_BALANCE_TO` activity, which Square uses to add money to
    a gift card as the result of a transfer from another gift card.
    """

    transfer_balance_from_activity_details: typing.Optional[GiftCardActivityTransferBalanceFrom] = pydantic.Field(
        default=None
    )
    """
    Additional details about a `TRANSFER_BALANCE_FROM` activity, which Square uses to deduct money from
    a gift as the result of a transfer to another gift card.
    """

    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
