class ShoppingItem {
  final int productId;
  final String name;
  final double quantity;
  final String unit;

  const ShoppingItem({
    required this.productId,
    required this.name,
    required this.quantity,
    required this.unit,
  });

  factory ShoppingItem.fromJson(Map<String, dynamic> json) {
    final rawId = json['productId'];
    final rawQuantity = json['quantity'];

    return ShoppingItem(
      productId: rawId is num ? rawId.toInt() : int.parse(rawId.toString()),
      name: json['name'].toString(),
      quantity: rawQuantity is num
          ? rawQuantity.toDouble()
          : double.parse(rawQuantity.toString()),
      unit: json['unit'].toString(),
    );
  }
}