"""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.product import (
    Product,
)
from mindbodypublicapi.models.service import (
    Service,
)


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

    Attributes:
        id (int): The ID of the package.
        name (str): The name of the package.
        discount_percentage (float): The discount percentage applied to the package.
        sell_online (bool): When `true`, only products that can be sold online are
            returned.<br />  When `false`, all products are returned.
        services (List[Service]): Information about the services in the packages.
        products (List[Product]): Information about the products in the packages.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "id": "Id",
        "name": "Name",
        "discount_percentage": "DiscountPercentage",
        "sell_online": "SellOnline",
        "services": "Services",
        "products": "Products",
    }

    _optionals = [
        "id",
        "name",
        "discount_percentage",
        "sell_online",
        "services",
        "products",
    ]

    def __init__(
        self,
        id=APIHelper.SKIP,
        name=APIHelper.SKIP,
        discount_percentage=APIHelper.SKIP,
        sell_online=APIHelper.SKIP,
        services=APIHelper.SKIP,
        products=APIHelper.SKIP):
        """Initialize a Package instance."""
        # Initialize members of the class
        if id is not APIHelper.SKIP:
            self.id = id
        if name is not APIHelper.SKIP:
            self.name = name
        if discount_percentage is not APIHelper.SKIP:
            self.discount_percentage = discount_percentage
        if sell_online is not APIHelper.SKIP:
            self.sell_online = sell_online
        if services is not APIHelper.SKIP:
            self.services = services
        if products is not APIHelper.SKIP:
            self.products = products

    @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
        id =\
            dictionary.get("Id")\
            if dictionary.get("Id")\
                else APIHelper.SKIP
        name =\
            dictionary.get("Name")\
            if dictionary.get("Name")\
                else APIHelper.SKIP
        discount_percentage =\
            dictionary.get("DiscountPercentage")\
            if dictionary.get("DiscountPercentage")\
                else APIHelper.SKIP
        sell_online =\
            dictionary.get("SellOnline")\
            if "SellOnline" in dictionary.keys()\
                else APIHelper.SKIP
        services = None
        if dictionary.get("Services") is not None:
            services = [
                Service.from_dictionary(x)
                    for x in dictionary.get("Services")
            ]
        else:
            services = APIHelper.SKIP
        products = None
        if dictionary.get("Products") is not None:
            products = [
                Product.from_dictionary(x)
                    for x in dictionary.get("Products")
            ]
        else:
            products = APIHelper.SKIP

        # Return an object of this model
        return cls(id,
                   name,
                   discount_percentage,
                   sell_online,
                   services,
                   products)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _name=(
            self.name
            if hasattr(self, "name")
            else None
        )
        _discount_percentage=(
            self.discount_percentage
            if hasattr(self, "discount_percentage")
            else None
        )
        _sell_online=(
            self.sell_online
            if hasattr(self, "sell_online")
            else None
        )
        _services=(
            self.services
            if hasattr(self, "services")
            else None
        )
        _products=(
            self.products
            if hasattr(self, "products")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"id={_id!r}, "
            f"name={_name!r}, "
            f"discount_percentage={_discount_percentage!r}, "
            f"sell_online={_sell_online!r}, "
            f"services={_services!r}, "
            f"products={_products!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _name=(
            self.name
            if hasattr(self, "name")
            else None
        )
        _discount_percentage=(
            self.discount_percentage
            if hasattr(self, "discount_percentage")
            else None
        )
        _sell_online=(
            self.sell_online
            if hasattr(self, "sell_online")
            else None
        )
        _services=(
            self.services
            if hasattr(self, "services")
            else None
        )
        _products=(
            self.products
            if hasattr(self, "products")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"id={_id!s}, "
            f"name={_name!s}, "
            f"discount_percentage={_discount_percentage!s}, "
            f"sell_online={_sell_online!s}, "
            f"services={_services!s}, "
            f"products={_products!s}, "
            f")"
        )
