Files
recipe-app/flutter/lib/features/import/domain/parsed_receipt_item.dart
T
Nils-Johan Gynther d92272e554
Test Suite / test (24.15.0) (push) Has been cancelled
feat: implement matchedVia tracking for receipt items and enhance user alias management
2026-05-07 13:57:41 +02:00

83 lines
2.8 KiB
Dart

/// Model for a parsed receipt item from the receipt import API.
class ParsedReceiptItem {
final String rawName;
final double? quantity;
final String? unit;
final double? price;
final String? brand;
final String? origin;
// alias-match (säker, ingen bekräftelse behövs)
final int? matchedProductId;
final String? matchedProductName;
// ordbaserad match (kräver bekräftelse)
final int? suggestedProductId;
final String? suggestedProductName;
// AI-kategorisuggestion (premium)
final String? categorySuggestionName;
final String? categorySuggestionPath;
final int? categorySuggestionId;
// matchkälla för UI-visning: 'alias' | 'wordmatch' | 'ai' | 'none'
final String? matchedVia;
ParsedReceiptItem({
required this.rawName,
this.quantity,
this.unit,
this.price,
this.brand,
this.origin,
this.matchedProductId,
this.matchedProductName,
this.suggestedProductId,
this.suggestedProductName,
this.categorySuggestionName,
this.categorySuggestionPath,
this.categorySuggestionId,
this.matchedVia,
});
factory ParsedReceiptItem.fromJson(Map<String, dynamic> json) {
final cat = json['categorySuggestion'] as Map<String, dynamic>?;
return ParsedReceiptItem(
rawName: json['rawName'] as String? ?? '',
quantity: (json['quantity'] as num?)?.toDouble(),
unit: json['unit'] as String?,
price: (json['price'] as num?)?.toDouble(),
brand: json['brand'] as String?,
origin: json['origin'] as String?,
matchedProductId: (json['matchedProductId'] as num?)?.toInt(),
matchedProductName: json['matchedProductName'] as String?,
suggestedProductId: (json['suggestedProductId'] as num?)?.toInt(),
suggestedProductName: json['suggestedProductName'] as String?,
categorySuggestionName: cat?['categoryName'] as String?,
categorySuggestionPath: cat?['path'] as String?,
categorySuggestionId: (cat?['categoryId'] as num?)?.toInt(),
matchedVia: json['matchedVia'] as String?,
);
}
Map<String, dynamic> toJson() {
return {
'rawName': rawName,
'quantity': quantity,
'unit': unit,
'price': price,
'brand': brand,
'origin': origin,
'matchedProductId': matchedProductId,
'matchedProductName': matchedProductName,
'suggestedProductId': suggestedProductId,
'suggestedProductName': suggestedProductName,
if (categorySuggestionId != null ||
categorySuggestionName != null ||
categorySuggestionPath != null)
'categorySuggestion': {
'categoryId': categorySuggestionId,
'categoryName': categorySuggestionName,
'path': categorySuggestionPath,
},
if (matchedVia != null) 'matchedVia': matchedVia,
};
}
}