"""cellpointapi.

This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
"""

# ruff: noqa: E501
from cellpointapi.api_helper import APIHelper
from cellpointapi.models.non_positive_amount import (
    NonPositiveAmount,
)


class DiscountData(object):
    """Implementation of the 'DiscountData' model.

    Promotion code applied to the order.

    Attributes:
        discount_code (str): The code that has been applied as a promotion.
        discount_amount (NonPositiveAmount): An amount that is a nonpositive number,
            i.e. {0, -1, -2, -3, -4, -5,…}
        additional_properties (Dict[str, Any]): The additional properties for the
            model.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "discount_code": "discountCode",
        "discount_amount": "discountAmount",
    }

    def __init__(
        self,
        discount_code=None,
        discount_amount=None,
        additional_properties=None):
        """Initialize a DiscountData instance."""
        # Initialize members of the class
        self.discount_code = discount_code
        self.discount_amount = discount_amount

        # Add additional model properties to the instance
        if additional_properties is None:
            additional_properties = {}
        self.additional_properties = additional_properties

    @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
        discount_code =\
            dictionary.get("discountCode")\
            if dictionary.get("discountCode")\
                else None
        discount_amount =\
            NonPositiveAmount.from_dictionary(
                dictionary.get("discountAmount"))\
                if dictionary.get("discountAmount") else None

        additional_properties = APIHelper.get_additional_properties(
            dictionary={k: v for k, v in dictionary.items()
                        if k not in cls._names.values()},
            unboxing_function=lambda value: value)

        # Return an object of this model
        return cls(discount_code,
                   discount_amount,
                   additional_properties)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _discount_code=self.discount_code
        _discount_amount=self.discount_amount
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"discount_code={_discount_code!r}, "
            f"discount_amount={_discount_amount!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _discount_code=self.discount_code
        _discount_amount=self.discount_amount
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"discount_code={_discount_code!s}, "
            f"discount_amount={_discount_amount!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
