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

"""
paypalserversdk

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


class Frequency(object):

    """Implementation of the 'Frequency' model.

    The frequency of the billing cycle.

    Attributes:
        interval_unit (IntervalUnit): The interval at which the subscription
            is charged or billed.
        interval_count (int): The number of intervals after which a subscriber
            is billed. For example, if the `interval_unit` is `DAY` with an
            `interval_count` of  `2`, the subscription is billed once every
            two days. The following table lists the maximum allowed values for
            the `interval_count` for each `interval_unit`: Interval unit
            Maximum interval count DAY 365 WEEK 52 MONTH 12 YEAR 1

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "interval_unit": 'interval_unit',
        "interval_count": 'interval_count'
    }

    _optionals = [
        'interval_count',
    ]

    def __init__(self,
                 interval_unit=None,
                 interval_count=1):
        """Constructor for the Frequency class"""

        # Initialize members of the class
        self.interval_unit = interval_unit 
        self.interval_count = interval_count 

    @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
        interval_unit = dictionary.get("interval_unit") if dictionary.get("interval_unit") else None
        interval_count = dictionary.get("interval_count") if dictionary.get("interval_count") else 1
        # Return an object of this model
        return cls(interval_unit,
                   interval_count)

    def __repr__(self):
        return (f'{self.__class__.__name__}('
                f'interval_unit={self.interval_unit!r}, '
                f'interval_count={(self.interval_count if hasattr(self, "interval_count") else None)!r})')

    def __str__(self):
        return (f'{self.__class__.__name__}('
                f'interval_unit={self.interval_unit!s}, '
                f'interval_count={(self.interval_count if hasattr(self, "interval_count") else None)!s})')
