"""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.pricing_scheme import (
    PricingScheme,
)


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

    The billing cycle providing details of the billing frequency, amount, duration
    and if the billing cycle is a free, discounted or regular billing cycle. The
    sequence of the billing cycle will be in the following order - free trial billing
    cycle(s), discounted trial billing cycle(s), regular billing cycle(s).

    Attributes:
        tenure_type (TenureType): The tenure type of the billing cycle identifies if
            the billing cycle is a trial(free or discounted) or regular billing cycle.
        pricing_scheme (PricingScheme): The pricing scheme details.
        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).
        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.
        start_date (str): The stand-alone date, in [Internet date and time
            format](https://tools.ietf.org/html/rfc3339#section-5.6). To represent
            special legal values, such as a date of birth, you should use dates with
            no associated time or time-zone data. Whenever possible, use the standard
            `date_time` type. This regular expression does not validate all dates.
            For example, February 31 is valid and nothing is known about leap years.

    """

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

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

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

    @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
        tenure_type =\
            dictionary.get("tenure_type")\
            if dictionary.get("tenure_type")\
                else None
        pricing_scheme =\
            PricingScheme.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
        sequence =\
            dictionary.get("sequence")\
            if dictionary.get("sequence")\
                else 1
        start_date =\
            dictionary.get("start_date")\
            if dictionary.get("start_date")\
                else APIHelper.SKIP

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

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

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