class Product {
String id;
String name;
double price;
int stockQuantity;
List<String> categories;
Product({
required this.id,
required this.name,
required this.price,
required this.stockQuantity,
required this.categories,
});
factory Product.fromJson(Map<String, dynamic> json) {
return Product(
id: json['id'] as String,
name: json['name'] as String,
price: json['price'] as double,
stockQuantity: json['stockQuantity'] as int,
categories: List<String>.from(json['categories'] as List<dynamic>),
);
}
void displayProductInfo() {
print('Product ID: $id');
print('Name: $name');
print('Price: \$${price.toStringAsFixed(2)}');
print('Stock Quantity: $stockQuantity');
print('Categories: ${categories.join(', ')}');
}
bool isInStock() {
return stockQuantity > 0;
}
}