"""paypalserversdk.

This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
"""

# ruff: noqa: E501
from paypalserversdk.api_helper import APIHelper
from paypalserversdk.models.network_transaction import (
    NetworkTransaction,
)


class CardStoredCredential(object):
    """Implementation of the 'Card Stored Credential' model.

    Provides additional details to process a payment using a `card` that has been
    stored or is intended to be stored (also referred to as stored_credential or
    card-on-file). Parameter compatibility: `payment_type=ONE_TIME` is compatible
    only with `payment_initiator=CUSTOMER`. `usage=FIRST` is compatible only with
    `payment_initiator=CUSTOMER`. `previous_transaction_reference` or
    `previous_network_transaction_reference` is compatible only with
    `payment_initiator=MERCHANT`. Only one of the parameters -
    `previous_transaction_reference` and `previous_network_transaction_reference` -
    can be present in the request.

    Attributes:
        payment_initiator (PaymentInitiator): The person or party who initiated or
            triggered the payment.
        payment_type (StoredPaymentSourcePaymentType): Indicates the type of the
            stored payment_source payment.
        usage (StoredPaymentSourceUsageType): Indicates if this is a `first` or
            `subsequent` payment using a stored payment source (also referred to as
            stored credential or card on file).
        previous_network_transaction_reference (NetworkTransaction): Reference values
            used by the card network to identify a transaction.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "payment_initiator": "payment_initiator",
        "payment_type": "payment_type",
        "usage": "usage",
        "previous_network_transaction_reference":
            "previous_network_transaction_reference",
    }

    _optionals = [
        "usage",
        "previous_network_transaction_reference",
    ]

    def __init__(
        self,
        payment_initiator=None,
        payment_type=None,
        usage="DERIVED",
        previous_network_transaction_reference=APIHelper.SKIP):
        """Initialize a CardStoredCredential instance."""
        # Initialize members of the class
        self.payment_initiator = payment_initiator
        self.payment_type = payment_type
        self.usage = usage
        if previous_network_transaction_reference is not APIHelper.SKIP:
            self.previous_network_transaction_reference =\
                 previous_network_transaction_reference

    @classmethod
    def from_dictionary(cls,
                        dictionary):
        """Create an instance of this model from a dictionary

        Args:
            dictionary (dictionary): A dictionary representation of the object
            as obtained from the deserialization of the server's response. The
            keys MUST match property names in the API description.

        Returns:
            object: An instance of this structure class.

        """
        if not isinstance(dictionary, dict) or dictionary is None:
            return None

        # Extract variables from the dictionary
        payment_initiator =\
            dictionary.get("payment_initiator")\
            if dictionary.get("payment_initiator")\
                else None
        payment_type =\
            dictionary.get("payment_type")\
            if dictionary.get("payment_type")\
                else None
        usage =\
            dictionary.get("usage")\
            if dictionary.get("usage")\
                else "DERIVED"
        previous_network_transaction_reference =\
            NetworkTransaction.from_dictionary(
                dictionary.get("previous_network_transaction_reference"))\
                if "previous_network_transaction_reference" in dictionary.keys()\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(payment_initiator,
                   payment_type,
                   usage,
                   previous_network_transaction_reference)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _payment_initiator=self.payment_initiator
        _payment_type=self.payment_type
        _usage=(
            self.usage
            if hasattr(self, "usage")
            else None
        )
        _previous_network_transaction_reference=(
            self.previous_network_transaction_reference
            if hasattr(self, "previous_network_transaction_reference")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"payment_initiator={_payment_initiator!r}, "
            f"payment_type={_payment_type!r}, "
            f"usage={_usage!r}, "
            f"previous_network_transaction_reference={_previous_network_transaction_reference!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _payment_initiator=self.payment_initiator
        _payment_type=self.payment_type
        _usage=(
            self.usage
            if hasattr(self, "usage")
            else None
        )
        _previous_network_transaction_reference=(
            self.previous_network_transaction_reference
            if hasattr(self, "previous_network_transaction_reference")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"payment_initiator={_payment_initiator!s}, "
            f"payment_type={_payment_type!s}, "
            f"usage={_usage!s}, "
            f"previous_network_transaction_reference={_previous_network_transaction_reference!s}, "
            f")"
        )
