# Path: app/helpers/carts/data_classes.py
# class CartItem:
#     """
#     Data class for items in cart.
#     """
#     item_id: str
#     modify_time: str
#     uid: str
#     document_id: str = None
# 
#     @staticmethod
#     def deserialize(document):
#         """
#         Helper function for parsing a Firestore document to a CartItem object.
# 
#         Parameters:
#            document (DocumentSnapshot): A snapshot of Firestore document.
# 
#         Output:
#            A CartItem object.
#         """
# 
#         data = document.to_dict()
#         if data:
#             return CartItem(
#                 document_id=document.id,
#                 item_id=data.get('item_id'),
#                 modify_time=data.get('modify_time'),
#                 uid=data.get('uid')
#             )
# 
#         return None


from dataclasses import asdict
from google.cloud import firestore
from .data_classes import CartItem
import time
    """
    Helper function for getting all items in a cart.

    Parameters:
       uid (str): The unique ID of an user.

    Output:
       A list of CartItem.
    """

    cart = []
    query_results = firestore_client.collection('carts').where('uid', '==', uid).order_by('modify_time', direction=firestore.Query.DESCENDING).get()
    for result in query_results:
        item = CartItem.deserialize(result)
        cart.append(item)
    return cart


def add_to_cart(uid, item_id):
    """
    Helper function for adding an item to a cart.

    Parameters:
       uid (str): The unique ID of an user.
       item_id (str): The ID of an item.

    Output:
       None.
    """


# Path: app/helpers/carts/data_classes.py
# class CartItem:
#     """
#     Data class for items in cart.
#     """
#     item_id: str
#     modify_time: str
#     uid: str
#     document_id: str = None
# 
#     @staticmethod
#     def deserialize(document):
#         """
#         Helper function for parsing a Firestore document to a CartItem object.
# 
#         Parameters:
#            document (DocumentSnapshot): A snapshot of Firestore document.
# 
#         Output:
#            A CartItem object.
#         """
# 
#         data = document.to_dict()
#         if data:
#             return CartItem(
#                 document_id=document.id,
#                 item_id=data.get('item_id'),
#                 modify_time=data.get('modify_time'),
#                 uid=data.get('uid')
#             )
# 
#         return None


# Path: app/helpers/carts/helpers.py
from dataclasses import asdict
from google.cloud import firestore
from .data_classes import CartItem
import time

    """
    Helper function for getting all items in a cart.

    Parameters:
       uid (str): The unique ID of an user.

    Output:
       A list of CartItem.
    """

    cart = []
    query_results = firestore_client.collection('carts').where('uid', '==', uid).order_by('modify_time', direction=firestore.Query.DESCENDING).get()
    for result in query_results:
        item = CartItem.deserialize(result)
        cart.append(item)
    return cart


def add_to_cart(uid, item_id):
    """
    Helper function for adding an item to a cart.

    Parameters:
       uid (str): The unique ID of an user.
       item_id (str): The ID of an item.

    Output:
       None.
    """


    item = CartItem(