"""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.appointment import (
    Appointment,
)


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

    Attributes:
        item (Any): The model property of type Any.
        sales_notes (str): Sales Notes for the Product Purcahsed
        discount_amount (float): The amount of the discount applied to the item.
        visit_ids (List[int]): The IDs of the booked classes, enrollments, or courses
            that were reconciled by this cart item. This list is only returned if a
            valid visit ID was passed in the request’s `VisitIds` list.
        appointment_ids (List[int]): Gets or sets the item.
        appointments (List[Appointment]): The IDs of the appointments that were
            reconciled by this cart item. This list is only returned if a valid
            appointment ID was passed in the request’s `AppointmentIds` list.
        id (int): The item’s ID in the current cart.
        quantity (int): The quantity of the item being purchased.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "item": "Item",
        "sales_notes": "SalesNotes",
        "discount_amount": "DiscountAmount",
        "visit_ids": "VisitIds",
        "appointment_ids": "AppointmentIds",
        "appointments": "Appointments",
        "id": "Id",
        "quantity": "Quantity",
    }

    _optionals = [
        "item",
        "sales_notes",
        "discount_amount",
        "visit_ids",
        "appointment_ids",
        "appointments",
        "id",
        "quantity",
    ]

    def __init__(
        self,
        item=APIHelper.SKIP,
        sales_notes=APIHelper.SKIP,
        discount_amount=APIHelper.SKIP,
        visit_ids=APIHelper.SKIP,
        appointment_ids=APIHelper.SKIP,
        appointments=APIHelper.SKIP,
        id=APIHelper.SKIP,
        quantity=APIHelper.SKIP):
        """Initialize a CartItem instance."""
        # Initialize members of the class
        if item is not APIHelper.SKIP:
            self.item = item
        if sales_notes is not APIHelper.SKIP:
            self.sales_notes = sales_notes
        if discount_amount is not APIHelper.SKIP:
            self.discount_amount = discount_amount
        if visit_ids is not APIHelper.SKIP:
            self.visit_ids = visit_ids
        if appointment_ids is not APIHelper.SKIP:
            self.appointment_ids = appointment_ids
        if appointments is not APIHelper.SKIP:
            self.appointments = appointments
        if id is not APIHelper.SKIP:
            self.id = id
        if quantity is not APIHelper.SKIP:
            self.quantity = quantity

    @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
        item =\
            dictionary.get("Item")\
            if dictionary.get("Item")\
                else APIHelper.SKIP
        sales_notes =\
            dictionary.get("SalesNotes")\
            if dictionary.get("SalesNotes")\
                else APIHelper.SKIP
        discount_amount =\
            dictionary.get("DiscountAmount")\
            if dictionary.get("DiscountAmount")\
                else APIHelper.SKIP
        visit_ids =\
            dictionary.get("VisitIds")\
            if dictionary.get("VisitIds")\
                else APIHelper.SKIP
        appointment_ids =\
            dictionary.get("AppointmentIds")\
            if dictionary.get("AppointmentIds")\
                else APIHelper.SKIP
        appointments = None
        if dictionary.get("Appointments") is not None:
            appointments = [
                Appointment.from_dictionary(x)
                    for x in dictionary.get("Appointments")
            ]
        else:
            appointments = APIHelper.SKIP
        id =\
            dictionary.get("Id")\
            if dictionary.get("Id")\
                else APIHelper.SKIP
        quantity =\
            dictionary.get("Quantity")\
            if dictionary.get("Quantity")\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(item,
                   sales_notes,
                   discount_amount,
                   visit_ids,
                   appointment_ids,
                   appointments,
                   id,
                   quantity)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _item=(
            self.item
            if hasattr(self, "item")
            else None
        )
        _sales_notes=(
            self.sales_notes
            if hasattr(self, "sales_notes")
            else None
        )
        _discount_amount=(
            self.discount_amount
            if hasattr(self, "discount_amount")
            else None
        )
        _visit_ids=(
            self.visit_ids
            if hasattr(self, "visit_ids")
            else None
        )
        _appointment_ids=(
            self.appointment_ids
            if hasattr(self, "appointment_ids")
            else None
        )
        _appointments=(
            self.appointments
            if hasattr(self, "appointments")
            else None
        )
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _quantity=(
            self.quantity
            if hasattr(self, "quantity")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"item={_item!r}, "
            f"sales_notes={_sales_notes!r}, "
            f"discount_amount={_discount_amount!r}, "
            f"visit_ids={_visit_ids!r}, "
            f"appointment_ids={_appointment_ids!r}, "
            f"appointments={_appointments!r}, "
            f"id={_id!r}, "
            f"quantity={_quantity!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _item=(
            self.item
            if hasattr(self, "item")
            else None
        )
        _sales_notes=(
            self.sales_notes
            if hasattr(self, "sales_notes")
            else None
        )
        _discount_amount=(
            self.discount_amount
            if hasattr(self, "discount_amount")
            else None
        )
        _visit_ids=(
            self.visit_ids
            if hasattr(self, "visit_ids")
            else None
        )
        _appointment_ids=(
            self.appointment_ids
            if hasattr(self, "appointment_ids")
            else None
        )
        _appointments=(
            self.appointments
            if hasattr(self, "appointments")
            else None
        )
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _quantity=(
            self.quantity
            if hasattr(self, "quantity")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"item={_item!s}, "
            f"sales_notes={_sales_notes!s}, "
            f"discount_amount={_discount_amount!s}, "
            f"visit_ids={_visit_ids!s}, "
            f"appointment_ids={_appointment_ids!s}, "
            f"appointments={_appointments!s}, "
            f"id={_id!s}, "
            f"quantity={_quantity!s}, "
            f")"
        )
