"""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.frequency import (
    Frequency,
)
from paypalserversdk.models.subscription_pricing_scheme import (
    SubscriptionPricingScheme,
)


class SubscriptionBillingCycle(object):
    """Implementation of the 'Subscription Billing Cycle' model.

    The billing cycle details.

    Attributes:
        pricing_scheme (SubscriptionPricingScheme): The pricing scheme details.
        frequency (Frequency): The frequency of the billing cycle.
        tenure_type (TenureType): The tenure type of the billing cycle. In case of a
            plan having trial cycle, only 2 trial cycles are allowed per plan.
        sequence (int): The order in which this cycle is to run among other billing
            cycles. For example, a trial billing cycle has a `sequence` of `1` while
            a regular billing cycle has a `sequence` of `2`, so that trial cycle runs
            before the regular cycle.
        total_cycles (int): The number of times this billing cycle gets executed.
            Trial billing cycles can only be executed a finite number of times (value
            between 1 and 999 for total_cycles). Regular billing cycles can be
            executed infinite times (value of 0 for total_cycles) or a finite number
            of times (value between 1 and 999 for total_cycles).

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "frequency": "frequency",
        "tenure_type": "tenure_type",
        "sequence": "sequence",
        "pricing_scheme": "pricing_scheme",
        "total_cycles": "total_cycles",
    }

    _optionals = [
        "pricing_scheme",
        "total_cycles",
    ]

    def __init__(
        self,
        frequency=None,
        tenure_type=None,
        sequence=None,
        pricing_scheme=APIHelper.SKIP,
        total_cycles=1):
        """Initialize a SubscriptionBillingCycle instance."""
        # Initialize members of the class
        if pricing_scheme is not APIHelper.SKIP:
            self.pricing_scheme = pricing_scheme
        self.frequency = frequency
        self.tenure_type = tenure_type
        self.sequence = sequence
        self.total_cycles = total_cycles

    @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
        frequency =\
            Frequency.from_dictionary(
                dictionary.get("frequency"))\
                if dictionary.get("frequency") else None
        tenure_type =\
            dictionary.get("tenure_type")\
            if dictionary.get("tenure_type")\
                else None
        sequence =\
            dictionary.get("sequence")\
            if dictionary.get("sequence")\
                else None
        pricing_scheme =\
            SubscriptionPricingScheme.from_dictionary(
                dictionary.get("pricing_scheme"))\
                if "pricing_scheme" in dictionary.keys()\
                else APIHelper.SKIP
        total_cycles =\
            dictionary.get("total_cycles")\
            if dictionary.get("total_cycles")\
                else 1

        # Return an object of this model
        return cls(frequency,
                   tenure_type,
                   sequence,
                   pricing_scheme,
                   total_cycles)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _pricing_scheme=(
            self.pricing_scheme
            if hasattr(self, "pricing_scheme")
            else None
        )
        _frequency=self.frequency
        _tenure_type=self.tenure_type
        _sequence=self.sequence
        _total_cycles=(
            self.total_cycles
            if hasattr(self, "total_cycles")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"pricing_scheme={_pricing_scheme!r}, "
            f"frequency={_frequency!r}, "
            f"tenure_type={_tenure_type!r}, "
            f"sequence={_sequence!r}, "
            f"total_cycles={_total_cycles!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _pricing_scheme=(
            self.pricing_scheme
            if hasattr(self, "pricing_scheme")
            else None
        )
        _frequency=self.frequency
        _tenure_type=self.tenure_type
        _sequence=self.sequence
        _total_cycles=(
            self.total_cycles
            if hasattr(self, "total_cycles")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"pricing_scheme={_pricing_scheme!s}, "
            f"frequency={_frequency!s}, "
            f"tenure_type={_tenure_type!s}, "
            f"sequence={_sequence!s}, "
            f"total_cycles={_total_cycles!s}, "
            f")"
        )
