"""mindbodypublicapi.

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

# ruff: noqa: E501
from mindbodypublicapi.api_helper import APIHelper
from mindbodypublicapi.models.applicable_item import (
    ApplicableItem,
)
from mindbodypublicapi.models.discount import (
    Discount,
)


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

    Attributes:
        code (str): The code of the promocode.
        name (str): The name of the promocode.
        active (bool): Indicates that promocode is active. Default: **true**
        discount (Discount): Discount for a promo code
        activation_date (datetime): The date of the promocode activation. Default:
            **today’s date**
        expiration_date (datetime): The date of the promocode expiration. Default:
            **a months from today’s date**
        max_uses (int): The maximun number of uses. A use is considered a single sale.
        days_after_close_date (int): The number of days a client has to use a
            promocode after they are no longer a prospect.
        allow_online (bool): Indicates if promocode can be redeemed online in
            consumer mode. Default: **false**
        days_valid (List[str]): Indicates what days of the week promocode is valid.
            Defaults to 7 days of the week. Possible values are:  * Monday  * Tuesday
            * Wednesday  * Thursday  * Friday  * Saturday  * Sunday
        applicable_items (List[ApplicableItem]): Contains information about a
            promocode applicable items.  See ApplicableItems for a details of the
            `ApplicableItems` object.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "code": "Code",
        "name": "Name",
        "active": "Active",
        "discount": "Discount",
        "activation_date": "ActivationDate",
        "expiration_date": "ExpirationDate",
        "max_uses": "MaxUses",
        "days_after_close_date": "DaysAfterCloseDate",
        "allow_online": "AllowOnline",
        "days_valid": "DaysValid",
        "applicable_items": "ApplicableItems",
    }

    _optionals = [
        "active",
        "discount",
        "activation_date",
        "expiration_date",
        "max_uses",
        "days_after_close_date",
        "allow_online",
        "days_valid",
        "applicable_items",
    ]

    def __init__(
        self,
        code=None,
        name=None,
        active=APIHelper.SKIP,
        discount=APIHelper.SKIP,
        activation_date=APIHelper.SKIP,
        expiration_date=APIHelper.SKIP,
        max_uses=APIHelper.SKIP,
        days_after_close_date=APIHelper.SKIP,
        allow_online=APIHelper.SKIP,
        days_valid=APIHelper.SKIP,
        applicable_items=APIHelper.SKIP):
        """Initialize a AddPromoCodeRequest instance."""
        # Initialize members of the class
        self.code = code
        self.name = name
        if active is not APIHelper.SKIP:
            self.active = active
        if discount is not APIHelper.SKIP:
            self.discount = discount
        if activation_date is not APIHelper.SKIP:
            self.activation_date =\
                 APIHelper.apply_datetime_converter(
                activation_date, APIHelper.RFC3339DateTime)\
                 if activation_date else None
        if expiration_date is not APIHelper.SKIP:
            self.expiration_date =\
                 APIHelper.apply_datetime_converter(
                expiration_date, APIHelper.RFC3339DateTime)\
                 if expiration_date else None
        if max_uses is not APIHelper.SKIP:
            self.max_uses = max_uses
        if days_after_close_date is not APIHelper.SKIP:
            self.days_after_close_date = days_after_close_date
        if allow_online is not APIHelper.SKIP:
            self.allow_online = allow_online
        if days_valid is not APIHelper.SKIP:
            self.days_valid = days_valid
        if applicable_items is not APIHelper.SKIP:
            self.applicable_items = applicable_items

    @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
        code =\
            dictionary.get("Code")\
            if dictionary.get("Code")\
                else None
        name =\
            dictionary.get("Name")\
            if dictionary.get("Name")\
                else None
        active =\
            dictionary.get("Active")\
            if "Active" in dictionary.keys()\
                else APIHelper.SKIP
        discount =\
            Discount.from_dictionary(
                dictionary.get("Discount"))\
                if "Discount" in dictionary.keys()\
                else APIHelper.SKIP
        activation_date = APIHelper.RFC3339DateTime.from_value(
            dictionary.get("ActivationDate")).datetime\
            if dictionary.get("ActivationDate") else APIHelper.SKIP
        expiration_date = APIHelper.RFC3339DateTime.from_value(
            dictionary.get("ExpirationDate")).datetime\
            if dictionary.get("ExpirationDate") else APIHelper.SKIP
        max_uses =\
            dictionary.get("MaxUses")\
            if dictionary.get("MaxUses")\
                else APIHelper.SKIP
        days_after_close_date =\
            dictionary.get("DaysAfterCloseDate")\
            if dictionary.get("DaysAfterCloseDate")\
                else APIHelper.SKIP
        allow_online =\
            dictionary.get("AllowOnline")\
            if "AllowOnline" in dictionary.keys()\
                else APIHelper.SKIP
        days_valid =\
            dictionary.get("DaysValid")\
            if dictionary.get("DaysValid")\
                else APIHelper.SKIP
        applicable_items = None
        if dictionary.get("ApplicableItems") is not None:
            applicable_items = [
                ApplicableItem.from_dictionary(x)
                    for x in dictionary.get("ApplicableItems")
            ]
        else:
            applicable_items = APIHelper.SKIP

        # Return an object of this model
        return cls(code,
                   name,
                   active,
                   discount,
                   activation_date,
                   expiration_date,
                   max_uses,
                   days_after_close_date,
                   allow_online,
                   days_valid,
                   applicable_items)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _code=self.code
        _name=self.name
        _active=(
            self.active
            if hasattr(self, "active")
            else None
        )
        _discount=(
            self.discount
            if hasattr(self, "discount")
            else None
        )
        _activation_date=(
            self.activation_date
            if hasattr(self, "activation_date")
            else None
        )
        _expiration_date=(
            self.expiration_date
            if hasattr(self, "expiration_date")
            else None
        )
        _max_uses=(
            self.max_uses
            if hasattr(self, "max_uses")
            else None
        )
        _days_after_close_date=(
            self.days_after_close_date
            if hasattr(self, "days_after_close_date")
            else None
        )
        _allow_online=(
            self.allow_online
            if hasattr(self, "allow_online")
            else None
        )
        _days_valid=(
            self.days_valid
            if hasattr(self, "days_valid")
            else None
        )
        _applicable_items=(
            self.applicable_items
            if hasattr(self, "applicable_items")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"code={_code!r}, "
            f"name={_name!r}, "
            f"active={_active!r}, "
            f"discount={_discount!r}, "
            f"activation_date={_activation_date!r}, "
            f"expiration_date={_expiration_date!r}, "
            f"max_uses={_max_uses!r}, "
            f"days_after_close_date={_days_after_close_date!r}, "
            f"allow_online={_allow_online!r}, "
            f"days_valid={_days_valid!r}, "
            f"applicable_items={_applicable_items!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _code=self.code
        _name=self.name
        _active=(
            self.active
            if hasattr(self, "active")
            else None
        )
        _discount=(
            self.discount
            if hasattr(self, "discount")
            else None
        )
        _activation_date=(
            self.activation_date
            if hasattr(self, "activation_date")
            else None
        )
        _expiration_date=(
            self.expiration_date
            if hasattr(self, "expiration_date")
            else None
        )
        _max_uses=(
            self.max_uses
            if hasattr(self, "max_uses")
            else None
        )
        _days_after_close_date=(
            self.days_after_close_date
            if hasattr(self, "days_after_close_date")
            else None
        )
        _allow_online=(
            self.allow_online
            if hasattr(self, "allow_online")
            else None
        )
        _days_valid=(
            self.days_valid
            if hasattr(self, "days_valid")
            else None
        )
        _applicable_items=(
            self.applicable_items
            if hasattr(self, "applicable_items")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"code={_code!s}, "
            f"name={_name!s}, "
            f"active={_active!s}, "
            f"discount={_discount!s}, "
            f"activation_date={_activation_date!s}, "
            f"expiration_date={_expiration_date!s}, "
            f"max_uses={_max_uses!s}, "
            f"days_after_close_date={_days_after_close_date!s}, "
            f"allow_online={_allow_online!s}, "
            f"days_valid={_days_valid!s}, "
            f"applicable_items={_applicable_items!s}, "
            f")"
        )
