"""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 BundledDiscount(object):
    """Implementation of the 'BundledDiscount' model.

    Represents a discount that is part of a bundle.

    Attributes:
        mtype (str): Discriminator used to identify the type of line item.
        title (str): What should be shown as the title of the line item on a receipt
            or billing summary.
        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 = {
        "mtype": "type",
        "title": "title",
        "discount_code": "discountCode",
        "discount_amount": "discountAmount",
    }

    def __init__(
        self,
        title=None,
        discount_code=None,
        discount_amount=None,
        additional_properties=None):
        """Initialize a BundledDiscount instance."""
        # Initialize members of the class
        self.mtype = "DISCOUNT"
        self.title = title
        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
        title =\
            dictionary.get("title")\
            if dictionary.get("title")\
                else None
        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(title,
                   discount_code,
                   discount_amount,
                   additional_properties)

    @classmethod
    def validate(cls, dictionary):
        """Validate dictionary against class required properties

        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:
            boolean : if dictionary is valid contains required properties.

        """
        if isinstance(dictionary, cls):
            return APIHelper.is_valid_type(
                    value=dictionary.mtype,
                    type_callable=lambda value:
                        isinstance(
                        value,
                        str,
                )) \
                and APIHelper.is_valid_type(
                    value=dictionary.title,
                    type_callable=lambda value:
                        isinstance(
                        value,
                        str,
                )) \
                and APIHelper.is_valid_type(
                    value=dictionary.discount_code,
                    type_callable=lambda value:
                        isinstance(
                        value,
                        str,
                )) \
                and APIHelper.is_valid_type(
                    value=dictionary.discount_amount,
                    type_callable=lambda value:
                        NonPositiveAmount.validate(value),
                    is_model_dict=True)

        if not isinstance(dictionary, dict):
            return False

        return APIHelper.is_valid_type(
                value=dictionary.get("type"),
                type_callable=lambda value:
                    isinstance(
                    value,
                    str,
            )) \
            and APIHelper.is_valid_type(
                value=dictionary.get("title"),
                type_callable=lambda value:
                    isinstance(
                    value,
                    str,
            )) \
            and APIHelper.is_valid_type(
                value=dictionary.get("discountCode"),
                type_callable=lambda value:
                    isinstance(
                    value,
                    str,
            )) \
            and APIHelper.is_valid_type(
                value=dictionary.get("discountAmount"),
                type_callable=lambda value:
                    NonPositiveAmount.validate(value),
                is_model_dict=True)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _mtype=self.mtype
        _title=self.title
        _discount_code=self.discount_code
        _discount_amount=self.discount_amount
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"mtype={_mtype!r}, "
            f"title={_title!r}, "
            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."""
        _mtype=self.mtype
        _title=self.title
        _discount_code=self.discount_code
        _discount_amount=self.discount_amount
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"mtype={_mtype!s}, "
            f"title={_title!s}, "
            f"discount_code={_discount_code!s}, "
            f"discount_amount={_discount_amount!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
