"""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.billing_cycle import (
    BillingCycle,
)
from paypalserversdk.models.money import Money


class OrderBillingPlan(object):
    """Implementation of the 'Order Billing Plan' model.

    Metadata for merchant-managed recurring billing plans. Valid only during the
    saved payment method token or billing agreement creation.

    Attributes:
        billing_cycles (List[BillingCycle]): An array of billing cycles for trial
            billing and regular billing. A plan can have at most two trial cycles and
            only one regular cycle.
        setup_fee (Money): The currency and amount for a financial transaction, such
            as a balance or payment due.
        name (str): Name of the recurring plan.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "billing_cycles": "billing_cycles",
        "setup_fee": "setup_fee",
        "name": "name",
    }

    _optionals = [
        "setup_fee",
        "name",
    ]

    def __init__(
        self,
        billing_cycles=None,
        setup_fee=APIHelper.SKIP,
        name=APIHelper.SKIP):
        """Initialize a OrderBillingPlan instance."""
        # Initialize members of the class
        self.billing_cycles = billing_cycles
        if setup_fee is not APIHelper.SKIP:
            self.setup_fee = setup_fee
        if name is not APIHelper.SKIP:
            self.name = name

    @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
        billing_cycles = None
        if dictionary.get("billing_cycles") is not None:
            billing_cycles = [
                BillingCycle.from_dictionary(x)
                    for x in dictionary.get("billing_cycles")
            ]
        setup_fee =\
            Money.from_dictionary(
                dictionary.get("setup_fee"))\
                if "setup_fee" in dictionary.keys()\
                else APIHelper.SKIP
        name =\
            dictionary.get("name")\
            if dictionary.get("name")\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(billing_cycles,
                   setup_fee,
                   name)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _billing_cycles=self.billing_cycles
        _setup_fee=(
            self.setup_fee
            if hasattr(self, "setup_fee")
            else None
        )
        _name=(
            self.name
            if hasattr(self, "name")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"billing_cycles={_billing_cycles!r}, "
            f"setup_fee={_setup_fee!r}, "
            f"name={_name!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _billing_cycles=self.billing_cycles
        _setup_fee=(
            self.setup_fee
            if hasattr(self, "setup_fee")
            else None
        )
        _name=(
            self.name
            if hasattr(self, "name")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"billing_cycles={_billing_cycles!s}, "
            f"setup_fee={_setup_fee!s}, "
            f"name={_name!s}, "
            f")"
        )
