/// Domain Entity: Cart Item /// /// Represents a single item in a shopping cart. library; /// Cart Item Entity /// /// Contains item-level information: /// - Product reference /// - Quantity /// - Pricing class CartItem { /// Unique cart item identifier final String cartItemId; /// Cart ID this item belongs to final String cartId; /// Product ID final String productId; /// Quantity ordered final double quantity; /// Unit price at time of adding to cart final double unitPrice; /// Subtotal (quantity * unitPrice) final double subtotal; /// Timestamp when item was added final DateTime addedAt; const CartItem({ required this.cartItemId, required this.cartId, required this.productId, required this.quantity, required this.unitPrice, required this.subtotal, required this.addedAt, }); /// Calculate subtotal (for verification) double get calculatedSubtotal => quantity * unitPrice; /// Copy with method for immutability CartItem copyWith({ String? cartItemId, String? cartId, String? productId, double? quantity, double? unitPrice, double? subtotal, DateTime? addedAt, }) { return CartItem( cartItemId: cartItemId ?? this.cartItemId, cartId: cartId ?? this.cartId, productId: productId ?? this.productId, quantity: quantity ?? this.quantity, unitPrice: unitPrice ?? this.unitPrice, subtotal: subtotal ?? this.subtotal, addedAt: addedAt ?? this.addedAt, ); } @override bool operator ==(Object other) { if (identical(this, other)) return true; return other is CartItem && other.cartItemId == cartItemId && other.cartId == cartId && other.productId == productId && other.quantity == quantity && other.unitPrice == unitPrice && other.subtotal == subtotal; } @override int get hashCode { return Object.hash( cartItemId, cartId, productId, quantity, unitPrice, subtotal, ); } @override String toString() { return 'CartItem(cartItemId: $cartItemId, productId: $productId, ' 'quantity: $quantity, unitPrice: $unitPrice, subtotal: $subtotal)'; } }