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


class SubscriptionPricingScheme(object):
    """Implementation of the 'Subscription Pricing Scheme' model.

    The pricing scheme details.

    Attributes:
        version (int): The version of the pricing scheme.
        fixed_price (Money): The currency and amount for a financial transaction,
            such as a balance or payment due.
        pricing_model (SubscriptionPricingModel): The pricing model for tiered plan.
            The `tiers` parameter is required.
        tiers (List[PricingTier]): An array of pricing tiers which are used for
            billing volume/tiered plans. pricing_model field has to be specified.
        create_time (str): The date and time, in [Internet date and time
            format](https://tools.ietf.org/html/rfc3339#section-5.6). Seconds are
            required while fractional seconds are optional. Note: The regular
            expression provides guidance but does not reject all invalid dates.
        update_time (str): The date and time, in [Internet date and time
            format](https://tools.ietf.org/html/rfc3339#section-5.6). Seconds are
            required while fractional seconds are optional. Note: The regular
            expression provides guidance but does not reject all invalid dates.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "version": "version",
        "fixed_price": "fixed_price",
        "pricing_model": "pricing_model",
        "tiers": "tiers",
        "create_time": "create_time",
        "update_time": "update_time",
    }

    _optionals = [
        "version",
        "fixed_price",
        "pricing_model",
        "tiers",
        "create_time",
        "update_time",
    ]

    def __init__(
        self,
        version=APIHelper.SKIP,
        fixed_price=APIHelper.SKIP,
        pricing_model=APIHelper.SKIP,
        tiers=APIHelper.SKIP,
        create_time=APIHelper.SKIP,
        update_time=APIHelper.SKIP):
        """Initialize a SubscriptionPricingScheme instance."""
        # Initialize members of the class
        if version is not APIHelper.SKIP:
            self.version = version
        if fixed_price is not APIHelper.SKIP:
            self.fixed_price = fixed_price
        if pricing_model is not APIHelper.SKIP:
            self.pricing_model = pricing_model
        if tiers is not APIHelper.SKIP:
            self.tiers = tiers
        if create_time is not APIHelper.SKIP:
            self.create_time = create_time
        if update_time is not APIHelper.SKIP:
            self.update_time = update_time

    @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
        version =\
            dictionary.get("version")\
            if dictionary.get("version")\
                else APIHelper.SKIP
        fixed_price =\
            Money.from_dictionary(
                dictionary.get("fixed_price"))\
                if "fixed_price" in dictionary.keys()\
                else APIHelper.SKIP
        pricing_model =\
            dictionary.get("pricing_model")\
            if dictionary.get("pricing_model")\
                else APIHelper.SKIP
        tiers = None
        if dictionary.get("tiers") is not None:
            tiers = [
                PricingTier.from_dictionary(x)
                    for x in dictionary.get("tiers")
            ]
        else:
            tiers = APIHelper.SKIP
        create_time =\
            dictionary.get("create_time")\
            if dictionary.get("create_time")\
                else APIHelper.SKIP
        update_time =\
            dictionary.get("update_time")\
            if dictionary.get("update_time")\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(version,
                   fixed_price,
                   pricing_model,
                   tiers,
                   create_time,
                   update_time)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _version=(
            self.version
            if hasattr(self, "version")
            else None
        )
        _fixed_price=(
            self.fixed_price
            if hasattr(self, "fixed_price")
            else None
        )
        _pricing_model=(
            self.pricing_model
            if hasattr(self, "pricing_model")
            else None
        )
        _tiers=(
            self.tiers
            if hasattr(self, "tiers")
            else None
        )
        _create_time=(
            self.create_time
            if hasattr(self, "create_time")
            else None
        )
        _update_time=(
            self.update_time
            if hasattr(self, "update_time")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"version={_version!r}, "
            f"fixed_price={_fixed_price!r}, "
            f"pricing_model={_pricing_model!r}, "
            f"tiers={_tiers!r}, "
            f"create_time={_create_time!r}, "
            f"update_time={_update_time!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _version=(
            self.version
            if hasattr(self, "version")
            else None
        )
        _fixed_price=(
            self.fixed_price
            if hasattr(self, "fixed_price")
            else None
        )
        _pricing_model=(
            self.pricing_model
            if hasattr(self, "pricing_model")
            else None
        )
        _tiers=(
            self.tiers
            if hasattr(self, "tiers")
            else None
        )
        _create_time=(
            self.create_time
            if hasattr(self, "create_time")
            else None
        )
        _update_time=(
            self.update_time
            if hasattr(self, "update_time")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"version={_version!s}, "
            f"fixed_price={_fixed_price!s}, "
            f"pricing_model={_pricing_model!s}, "
            f"tiers={_tiers!s}, "
            f"create_time={_create_time!s}, "
            f"update_time={_update_time!s}, "
            f")"
        )
