class FlyerImportItem {
  final int? flyerItemId;
  final String rawName;
  final String normalizedName;
  final String? category;
  final int? categoryId;
  final double? price;
  final String? priceUnit;
  final String? offerText;
  final bool isOffer;
  final String? offerLimitText;
  final double? comparisonPrice;
  final String? comparisonUnit;
  final double? parseConfidence;
  final List<String> parseReasons;
  final int? matchedProductId;
  final String? matchedProductName;
  final String? matchedVia;
  final double? matchConfidence;

  FlyerImportItem({
    required this.flyerItemId,
    required this.rawName,
    required this.normalizedName,
    this.category,
    this.categoryId,
    this.price,
    this.priceUnit,
    this.offerText,
    this.isOffer = false,
    this.offerLimitText,
    this.comparisonPrice,
    this.comparisonUnit,
    this.parseConfidence,
    this.parseReasons = const [],
    this.matchedProductId,
    this.matchedProductName,
    this.matchedVia,
    this.matchConfidence,
  });

  factory FlyerImportItem.fromJson(Map<String, dynamic> json) {
    return FlyerImportItem(
      flyerItemId: (json['flyerItemId'] as num?)?.toInt(),
      rawName: json['rawName'] as String? ?? '',
      normalizedName: json['normalizedName'] as String? ?? '',
      category: json['category'] as String?,
      categoryId: (json['categoryId'] as num?)?.toInt(),
      price: (json['price'] as num?)?.toDouble(),
      priceUnit: json['priceUnit'] as String?,
      offerText: json['offerText'] as String?,
      isOffer: json['isOffer'] == true,
      offerLimitText: json['offerLimitText'] as String?,
      comparisonPrice: (json['comparisonPrice'] as num?)?.toDouble(),
      comparisonUnit: json['comparisonUnit'] as String?,
      parseConfidence: (json['parseConfidence'] as num?)?.toDouble(),
      parseReasons: (json['parseReasons'] as List?)?.map((e) => e.toString()).toList() ?? const [],
      matchedProductId: (json['matchedProductId'] as num?)?.toInt(),
      matchedProductName: json['matchedProductName'] as String?,
      matchedVia: json['matchedVia'] as String?,
      matchConfidence: (json['matchConfidence'] as num?)?.toDouble(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'flyerItemId': flyerItemId,
      'rawName': rawName,
      'normalizedName': normalizedName,
      'category': category,
      'categoryId': categoryId,
      'price': price,
      'priceUnit': priceUnit,
      'offerText': offerText,
      'isOffer': isOffer,
      'offerLimitText': offerLimitText,
      'comparisonPrice': comparisonPrice,
      'comparisonUnit': comparisonUnit,
      'parseConfidence': parseConfidence,
      'parseReasons': parseReasons,
      'matchedProductId': matchedProductId,
      'matchedProductName': matchedProductName,
      'matchedVia': matchedVia,
      'matchConfidence': matchConfidence,
    };
  }

  FlyerImportItem copyWith({
    String? rawName,
    String? category,
    int? categoryId,
  }) {
    return FlyerImportItem(
      flyerItemId: flyerItemId,
      rawName: rawName ?? this.rawName,
      normalizedName: normalizedName,
      category: category ?? this.category,
      categoryId: categoryId ?? this.categoryId,
      price: price,
      priceUnit: priceUnit,
      offerText: offerText,
      isOffer: isOffer,
      offerLimitText: offerLimitText,
      comparisonPrice: comparisonPrice,
      comparisonUnit: comparisonUnit,
      parseConfidence: parseConfidence,
      parseReasons: parseReasons,
      matchedProductId: matchedProductId,
      matchedProductName: matchedProductName,
      matchedVia: matchedVia,
      matchConfidence: matchConfidence,
    );
  }
}
