# -*- coding: utf-8 -*-

"""
paypalserversdk

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""
from paypalserversdk.api_helper import APIHelper
from paypalserversdk.models.money import Money


class PaymentPreferencesOverride(object):

    """Implementation of the 'Payment Preferences Override' model.

    The payment preferences to override at subscription level.

    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=APIHelper.SKIP,
                 setup_fee=APIHelper.SKIP,
                 setup_fee_failure_action=APIHelper.SKIP,
                 payment_failure_threshold=APIHelper.SKIP):
        """Constructor for the PaymentPreferencesOverride class"""

        # Initialize members of the class
        if auto_bill_outstanding is not APIHelper.SKIP:
            self.auto_bill_outstanding = auto_bill_outstanding 
        if setup_fee is not APIHelper.SKIP:
            self.setup_fee = setup_fee 
        if setup_fee_failure_action is not APIHelper.SKIP:
            self.setup_fee_failure_action = setup_fee_failure_action 
        if payment_failure_threshold is not APIHelper.SKIP:
            self.payment_failure_threshold = payment_failure_threshold 

    @classmethod
    def from_dictionary(cls,
                        dictionary):
        """Creates 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 "auto_bill_outstanding" in dictionary.keys() else APIHelper.SKIP
        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 APIHelper.SKIP
        payment_failure_threshold = dictionary.get("payment_failure_threshold") if dictionary.get("payment_failure_threshold") else APIHelper.SKIP
        # Return an object of this model
        return cls(auto_bill_outstanding,
                   setup_fee,
                   setup_fee_failure_action,
                   payment_failure_threshold)

    def __repr__(self):
        return (f'{self.__class__.__name__}('
                f'auto_bill_outstanding={(self.auto_bill_outstanding if hasattr(self, "auto_bill_outstanding") else None)!r}, '
                f'setup_fee={(self.setup_fee if hasattr(self, "setup_fee") else None)!r}, '
                f'setup_fee_failure_action={(self.setup_fee_failure_action if hasattr(self, "setup_fee_failure_action") else None)!r}, '
                f'payment_failure_threshold={(self.payment_failure_threshold if hasattr(self, "payment_failure_threshold") else None)!r})')

    def __str__(self):
        return (f'{self.__class__.__name__}('
                f'auto_bill_outstanding={(self.auto_bill_outstanding if hasattr(self, "auto_bill_outstanding") else None)!s}, '
                f'setup_fee={(self.setup_fee if hasattr(self, "setup_fee") else None)!s}, '
                f'setup_fee_failure_action={(self.setup_fee_failure_action if hasattr(self, "setup_fee_failure_action") else None)!s}, '
                f'payment_failure_threshold={(self.payment_failure_threshold if hasattr(self, "payment_failure_threshold") else None)!s})')
