class InventoryItem { final int id; final int productId; final String productName; final double quantity; final String unit; final String? location; final String? brand; final String? purchaseDate; final String? bestBeforeDate; final bool opened; final String? comment; const InventoryItem({ required this.id, required this.productId, required this.productName, required this.quantity, required this.unit, this.location, this.brand, this.purchaseDate, this.bestBeforeDate, required this.opened, this.comment, }); factory InventoryItem.fromJson(Map json) { return InventoryItem( id: json['id'] as int, productId: json['productId'] as int, productName: (json['product'] as Map?)?['name'] as String? ?? '', quantity: double.tryParse(json['quantity']?.toString() ?? '0') ?? 0, unit: json['unit'] as String? ?? '', location: json['location'] as String?, brand: json['brand'] as String?, purchaseDate: json['purchaseDate'] as String?, bestBeforeDate: json['bestBeforeDate'] as String?, opened: json['opened'] as bool? ?? false, comment: json['comment'] as String?, ); } }