81 lines
2.0 KiB
Dart
81 lines
2.0 KiB
Dart
class Product {
|
|
final String id;
|
|
final String name;
|
|
final String category;
|
|
final int stockQuantity;
|
|
final int lowStockThreshold;
|
|
|
|
/// Never runs out; [stockQuantity] is left untouched by sales.
|
|
final bool infiniteStock;
|
|
final int priceInCents;
|
|
final String? imagePath;
|
|
final bool active;
|
|
|
|
const Product({
|
|
required this.id,
|
|
required this.name,
|
|
required this.category,
|
|
required this.stockQuantity,
|
|
required this.lowStockThreshold,
|
|
this.infiniteStock = false,
|
|
required this.priceInCents,
|
|
this.imagePath,
|
|
this.active = true,
|
|
});
|
|
|
|
bool get isOutOfStock => !infiniteStock && stockQuantity <= 0;
|
|
|
|
bool get isLowStock => !infiniteStock && stockQuantity <= lowStockThreshold;
|
|
|
|
Product copyWith({
|
|
String? id,
|
|
String? name,
|
|
String? category,
|
|
int? stockQuantity,
|
|
int? lowStockThreshold,
|
|
bool? infiniteStock,
|
|
int? priceInCents,
|
|
String? imagePath,
|
|
bool? active,
|
|
}) {
|
|
return Product(
|
|
id: id ?? this.id,
|
|
name: name ?? this.name,
|
|
category: category ?? this.category,
|
|
stockQuantity: stockQuantity ?? this.stockQuantity,
|
|
lowStockThreshold: lowStockThreshold ?? this.lowStockThreshold,
|
|
infiniteStock: infiniteStock ?? this.infiniteStock,
|
|
priceInCents: priceInCents ?? this.priceInCents,
|
|
imagePath: imagePath ?? this.imagePath,
|
|
active: active ?? this.active,
|
|
);
|
|
}
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is Product &&
|
|
id == other.id &&
|
|
name == other.name &&
|
|
category == other.category &&
|
|
stockQuantity == other.stockQuantity &&
|
|
lowStockThreshold == other.lowStockThreshold &&
|
|
infiniteStock == other.infiniteStock &&
|
|
priceInCents == other.priceInCents &&
|
|
imagePath == other.imagePath &&
|
|
active == other.active;
|
|
|
|
@override
|
|
int get hashCode => Object.hash(
|
|
id,
|
|
name,
|
|
category,
|
|
stockQuantity,
|
|
lowStockThreshold,
|
|
infiniteStock,
|
|
priceInCents,
|
|
imagePath,
|
|
active,
|
|
);
|
|
}
|