93 lines
1.9 KiB
Dart
93 lines
1.9 KiB
Dart
/// Domain Entity: Cart
|
|
///
|
|
/// Represents a shopping cart for a user.
|
|
library;
|
|
|
|
/// Cart Entity
|
|
///
|
|
/// Contains cart-level information:
|
|
/// - User ID
|
|
/// - Total amount
|
|
/// - Sync status
|
|
/// - Timestamps
|
|
class Cart {
|
|
/// Unique cart identifier
|
|
final String cartId;
|
|
|
|
/// User ID who owns this cart
|
|
final String userId;
|
|
|
|
/// Total cart amount
|
|
final double totalAmount;
|
|
|
|
/// Whether cart is synced with backend
|
|
final bool isSynced;
|
|
|
|
/// Last modification timestamp
|
|
final DateTime lastModified;
|
|
|
|
/// Cart creation timestamp
|
|
final DateTime createdAt;
|
|
|
|
const Cart({
|
|
required this.cartId,
|
|
required this.userId,
|
|
required this.totalAmount,
|
|
required this.isSynced,
|
|
required this.lastModified,
|
|
required this.createdAt,
|
|
});
|
|
|
|
/// Check if cart is empty
|
|
bool get isEmpty => totalAmount == 0;
|
|
|
|
/// Check if cart needs sync
|
|
bool get needsSync => !isSynced;
|
|
|
|
/// Copy with method for immutability
|
|
Cart copyWith({
|
|
String? cartId,
|
|
String? userId,
|
|
double? totalAmount,
|
|
bool? isSynced,
|
|
DateTime? lastModified,
|
|
DateTime? createdAt,
|
|
}) {
|
|
return Cart(
|
|
cartId: cartId ?? this.cartId,
|
|
userId: userId ?? this.userId,
|
|
totalAmount: totalAmount ?? this.totalAmount,
|
|
isSynced: isSynced ?? this.isSynced,
|
|
lastModified: lastModified ?? this.lastModified,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
);
|
|
}
|
|
|
|
@override
|
|
bool operator ==(Object other) {
|
|
if (identical(this, other)) return true;
|
|
|
|
return other is Cart &&
|
|
other.cartId == cartId &&
|
|
other.userId == userId &&
|
|
other.totalAmount == totalAmount &&
|
|
other.isSynced == isSynced;
|
|
}
|
|
|
|
@override
|
|
int get hashCode {
|
|
return Object.hash(
|
|
cartId,
|
|
userId,
|
|
totalAmount,
|
|
isSynced,
|
|
);
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
return 'Cart(cartId: $cartId, userId: $userId, totalAmount: $totalAmount, '
|
|
'isSynced: $isSynced, lastModified: $lastModified)';
|
|
}
|
|
}
|