/// A single line item within an [Order].
class OrderItem {
  final String productName;
  final String sku;
  final int quantity;
  final double unitPrice;

  /// Optional WooCommerce product ID for linking back to the catalog.
  final String? productId;

  /// Optional WooCommerce variation ID (for variable products).
  final String? variationId;

  /// Optional map of customization key/value pairs for custom order specs
  /// (e.g. `{'color': 'blue', 'size': 'large', 'material': 'cotton'}`).
  final Map<String, String> customizations;

  const OrderItem({
    required this.productName,
    required this.sku,
    required this.quantity,
    required this.unitPrice,
    this.productId,
    this.variationId,
    this.customizations = const {},
  });

  /// The total price for this line item.
  double get lineTotal => quantity * unitPrice;

  /// Returns a copy of this item with the given fields replaced.
  OrderItem copyWith({
    String? productName,
    String? sku,
    int? quantity,
    double? unitPrice,
    String? productId,
    String? variationId,
    Map<String, String>? customizations,
  }) {
    return OrderItem(
      productName: productName ?? this.productName,
      sku: sku ?? this.sku,
      quantity: quantity ?? this.quantity,
      unitPrice: unitPrice ?? this.unitPrice,
      productId: productId ?? this.productId,
      variationId: variationId ?? this.variationId,
      customizations: customizations ?? this.customizations,
    );
  }
}
