"""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.money import Money


class PaymentPreferences(object):
    """Implementation of the 'Payment Preferences' model.

    The payment preferences for a subscription.

    Attributes:
        auto_bill_outstanding (bool): Indicates whether to automatically bill the
            outstanding amount in the next billing cycle.
        setup_fee (Money): The currency and amount for a financial transaction, such
            as a balance or payment due.
        setup_fee_failure_action (SetupFeeFailureAction): The action to take on the
            subscription if the initial payment for the setup fails.
        payment_failure_threshold (int): The maximum number of payment failures
            before a subscription is suspended. For example, if
            `payment_failure_threshold` is `2`, the subscription automatically
            updates to the `SUSPEND` state if two consecutive payments fail.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "auto_bill_outstanding": "auto_bill_outstanding",
        "setup_fee": "setup_fee",
        "setup_fee_failure_action": "setup_fee_failure_action",
        "payment_failure_threshold": "payment_failure_threshold",
    }

    _optionals = [
        "auto_bill_outstanding",
        "setup_fee",
        "setup_fee_failure_action",
        "payment_failure_threshold",
    ]

    def __init__(
        self,
        auto_bill_outstanding=True,
        setup_fee=APIHelper.SKIP,
        setup_fee_failure_action="CANCEL",
        payment_failure_threshold=0):
        """Initialize a PaymentPreferences instance."""
        # Initialize members of the class
        self.auto_bill_outstanding = auto_bill_outstanding
        if setup_fee is not APIHelper.SKIP:
            self.setup_fee = setup_fee
        self.setup_fee_failure_action = setup_fee_failure_action
        self.payment_failure_threshold = payment_failure_threshold

    @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
        auto_bill_outstanding =\
            dictionary.get("auto_bill_outstanding")\
            if dictionary.get("auto_bill_outstanding")\
                else True
        setup_fee =\
            Money.from_dictionary(
                dictionary.get("setup_fee"))\
                if "setup_fee" in dictionary.keys()\
                else APIHelper.SKIP
        setup_fee_failure_action =\
            dictionary.get("setup_fee_failure_action")\
            if dictionary.get("setup_fee_failure_action")\
                else "CANCEL"
        payment_failure_threshold =\
            dictionary.get("payment_failure_threshold")\
            if dictionary.get("payment_failure_threshold")\
                else 0

        # Return an object of this model
        return cls(auto_bill_outstanding,
                   setup_fee,
                   setup_fee_failure_action,
                   payment_failure_threshold)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _auto_bill_outstanding=(
            self.auto_bill_outstanding
            if hasattr(self, "auto_bill_outstanding")
            else None
        )
        _setup_fee=(
            self.setup_fee
            if hasattr(self, "setup_fee")
            else None
        )
        _setup_fee_failure_action=(
            self.setup_fee_failure_action
            if hasattr(self, "setup_fee_failure_action")
            else None
        )
        _payment_failure_threshold=(
            self.payment_failure_threshold
            if hasattr(self, "payment_failure_threshold")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"auto_bill_outstanding={_auto_bill_outstanding!r}, "
            f"setup_fee={_setup_fee!r}, "
            f"setup_fee_failure_action={_setup_fee_failure_action!r}, "
            f"payment_failure_threshold={_payment_failure_threshold!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _auto_bill_outstanding=(
            self.auto_bill_outstanding
            if hasattr(self, "auto_bill_outstanding")
            else None
        )
        _setup_fee=(
            self.setup_fee
            if hasattr(self, "setup_fee")
            else None
        )
        _setup_fee_failure_action=(
            self.setup_fee_failure_action
            if hasattr(self, "setup_fee_failure_action")
            else None
        )
        _payment_failure_threshold=(
            self.payment_failure_threshold
            if hasattr(self, "payment_failure_threshold")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"auto_bill_outstanding={_auto_bill_outstanding!s}, "
            f"setup_fee={_setup_fee!s}, "
            f"setup_fee_failure_action={_setup_fee_failure_action!s}, "
            f"payment_failure_threshold={_payment_failure_threshold!s}, "
            f")"
        )
