class InventoryCompareItem {
  final int productId;
  final String name;
  final double requiredQuantity;
  final String unit;
  final double availableQuantity;
  final double missingQuantity;
  final String status;

  const InventoryCompareItem({
    required this.productId,
    required this.name,
    required this.requiredQuantity,
    required this.unit,
    required this.availableQuantity,
    required this.missingQuantity,
    required this.status,
  });

  factory InventoryCompareItem.fromJson(Map<String, dynamic> json) {
    final rawId = json['productId'];
    final rawRequired = json['required'];
    final rawAvailable = json['available'];
    final rawMissing = json['missing'];

    return InventoryCompareItem(
      productId: rawId is num ? rawId.toInt() : int.parse(rawId.toString()),
      name: json['name'].toString(),
      requiredQuantity: rawRequired is num
          ? rawRequired.toDouble()
          : double.parse(rawRequired.toString()),
      unit: json['unit'].toString(),
      availableQuantity: rawAvailable is num
          ? rawAvailable.toDouble()
          : double.parse(rawAvailable.toString()),
      missingQuantity: rawMissing is num
          ? rawMissing.toDouble()
          : double.parse(rawMissing.toString()),
      status: json['status'].toString(),
    );
  }
}