"""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.cart_item import (
    CartItem,
)
from mindbodypublicapi.models.transaction_response import (
    TransactionResponse,
)


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

    Represents a shopping cart.

    Attributes:
        id (str): The shopping cart ID.
        cart_items (List[CartItem]): Contains information about the items in the
            shopping cart.
        sub_total (float): The cart’s total cost before taxes and discounts were
            applied.
        discount_total (float): The monetary amount removed from the cart’s total
            cost by applied discounts.
        tax_total (float): The monetary amount paid in taxes, included in the cart’s
            `GrandTotal`.
        grand_total (float): The cart’s total cost, including taxes and discounts.
        transactions (List[TransactionResponse]): Contains information returned from
            the first call to CheckoutShoppingCart.
        sale_id (int): The ID of the sale associated with the shopping cart.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "id": "Id",
        "cart_items": "CartItems",
        "sub_total": "SubTotal",
        "discount_total": "DiscountTotal",
        "tax_total": "TaxTotal",
        "grand_total": "GrandTotal",
        "transactions": "Transactions",
        "sale_id": "SaleId",
    }

    _optionals = [
        "id",
        "cart_items",
        "sub_total",
        "discount_total",
        "tax_total",
        "grand_total",
        "transactions",
        "sale_id",
    ]

    def __init__(
        self,
        id=APIHelper.SKIP,
        cart_items=APIHelper.SKIP,
        sub_total=APIHelper.SKIP,
        discount_total=APIHelper.SKIP,
        tax_total=APIHelper.SKIP,
        grand_total=APIHelper.SKIP,
        transactions=APIHelper.SKIP,
        sale_id=APIHelper.SKIP):
        """Initialize a ShoppingCart instance."""
        # Initialize members of the class
        if id is not APIHelper.SKIP:
            self.id = id
        if cart_items is not APIHelper.SKIP:
            self.cart_items = cart_items
        if sub_total is not APIHelper.SKIP:
            self.sub_total = sub_total
        if discount_total is not APIHelper.SKIP:
            self.discount_total = discount_total
        if tax_total is not APIHelper.SKIP:
            self.tax_total = tax_total
        if grand_total is not APIHelper.SKIP:
            self.grand_total = grand_total
        if transactions is not APIHelper.SKIP:
            self.transactions = transactions
        if sale_id is not APIHelper.SKIP:
            self.sale_id = sale_id

    @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
        cart_items = None
        if dictionary.get("CartItems") is not None:
            cart_items = [
                CartItem.from_dictionary(x)
                    for x in dictionary.get("CartItems")
            ]
        else:
            cart_items = APIHelper.SKIP
        sub_total =\
            dictionary.get("SubTotal")\
            if dictionary.get("SubTotal")\
                else APIHelper.SKIP
        discount_total =\
            dictionary.get("DiscountTotal")\
            if dictionary.get("DiscountTotal")\
                else APIHelper.SKIP
        tax_total =\
            dictionary.get("TaxTotal")\
            if dictionary.get("TaxTotal")\
                else APIHelper.SKIP
        grand_total =\
            dictionary.get("GrandTotal")\
            if dictionary.get("GrandTotal")\
                else APIHelper.SKIP
        transactions = None
        if dictionary.get("Transactions") is not None:
            transactions = [
                TransactionResponse.from_dictionary(x)
                    for x in dictionary.get("Transactions")
            ]
        else:
            transactions = APIHelper.SKIP
        sale_id =\
            dictionary.get("SaleId")\
            if dictionary.get("SaleId")\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(id,
                   cart_items,
                   sub_total,
                   discount_total,
                   tax_total,
                   grand_total,
                   transactions,
                   sale_id)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _cart_items=(
            self.cart_items
            if hasattr(self, "cart_items")
            else None
        )
        _sub_total=(
            self.sub_total
            if hasattr(self, "sub_total")
            else None
        )
        _discount_total=(
            self.discount_total
            if hasattr(self, "discount_total")
            else None
        )
        _tax_total=(
            self.tax_total
            if hasattr(self, "tax_total")
            else None
        )
        _grand_total=(
            self.grand_total
            if hasattr(self, "grand_total")
            else None
        )
        _transactions=(
            self.transactions
            if hasattr(self, "transactions")
            else None
        )
        _sale_id=(
            self.sale_id
            if hasattr(self, "sale_id")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"id={_id!r}, "
            f"cart_items={_cart_items!r}, "
            f"sub_total={_sub_total!r}, "
            f"discount_total={_discount_total!r}, "
            f"tax_total={_tax_total!r}, "
            f"grand_total={_grand_total!r}, "
            f"transactions={_transactions!r}, "
            f"sale_id={_sale_id!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _cart_items=(
            self.cart_items
            if hasattr(self, "cart_items")
            else None
        )
        _sub_total=(
            self.sub_total
            if hasattr(self, "sub_total")
            else None
        )
        _discount_total=(
            self.discount_total
            if hasattr(self, "discount_total")
            else None
        )
        _tax_total=(
            self.tax_total
            if hasattr(self, "tax_total")
            else None
        )
        _grand_total=(
            self.grand_total
            if hasattr(self, "grand_total")
            else None
        )
        _transactions=(
            self.transactions
            if hasattr(self, "transactions")
            else None
        )
        _sale_id=(
            self.sale_id
            if hasattr(self, "sale_id")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"id={_id!s}, "
            f"cart_items={_cart_items!s}, "
            f"sub_total={_sub_total!s}, "
            f"discount_total={_discount_total!s}, "
            f"tax_total={_tax_total!s}, "
            f"grand_total={_grand_total!s}, "
            f"transactions={_transactions!s}, "
            f"sale_id={_sale_id!s}, "
            f")"
        )
