class CartItem {
  final String id;
  final String outletId;
  final String? image;
  final String name;
  final String variantName;
  final bool isProductVariant;
  final double sellingPrice;
  final String stockType;
  final double stock;
  final String unit;
  final int quantity;

  const CartItem({
    required this.id,
    required this.outletId,
    this.image,
    required this.name,
    required this.variantName,
    required this.isProductVariant,
    required this.sellingPrice,
    required this.stockType,
    required this.stock,
    required this.unit,
    required this.quantity,
  });

  CartItem copyWith({required int quantity}) {
    return CartItem(
      id: id,
      outletId: outletId,
      image: image,
      name: name,
      variantName: variantName,
      isProductVariant: isProductVariant,
      sellingPrice: sellingPrice,
      stockType: stockType,
      stock: stock,
      unit: unit,
      quantity: quantity,
    );
  }

  factory CartItem.fromJson(Map<String, dynamic> json) => CartItem(
    id: json['id'] as String,
    outletId: json['outlet_id'] as String,
    image: json['image'] as String?,
    name: json['name'] as String,
    variantName: json['variant_name'] as String,
    isProductVariant: json['is_product_variant'] as bool,
    sellingPrice: json['selling_price'] as double,
    stockType: json['stock_type'] as String,
    stock: json['stock'] as double,
    unit: json['unit'] as String,
    quantity: json['quantity'] as int,
  );

  Map<String, dynamic> toJson() => {
    'id': id,
    'outlet_id': outletId,
    'image': image,
    'name': name,
    'variant_name': variantName,
    'is_product_variant': isProductVariant,
    'selling_price': sellingPrice,
    'stock_type': stockType,
    'stock': stock,
    'unit': unit,
    'quantity': quantity,
  };
}
