class IngredientSuggestion { final int productId; final String productName; final double score; const IngredientSuggestion({ required this.productId, required this.productName, required this.score, }); factory IngredientSuggestion.fromJson(Map json) => IngredientSuggestion( productId: (json['productId'] as num).toInt(), productName: json['productName'] as String? ?? '', score: (json['score'] as num).toDouble(), ); } class ParsedIngredient { final String rawName; final String? rawLine; final double quantity; final String unit; final String? note; final List suggestions; final List alternatives; const ParsedIngredient({ required this.rawName, this.rawLine, required this.quantity, required this.unit, this.note, required this.suggestions, this.alternatives = const [], }); factory ParsedIngredient.fromJson(Map json) { final rawSuggestions = json['suggestions'] as List? ?? []; return ParsedIngredient( rawName: json['rawName'] as String? ?? '', rawLine: json['rawLine'] as String?, quantity: (json['quantity'] as num? ?? 0).toDouble(), unit: json['unit'] as String? ?? '', note: json['note'] as String?, suggestions: rawSuggestions .map((s) => IngredientSuggestion.fromJson(s as Map)) .toList(), alternatives: (json['alternatives'] as List? ?? []) .map((a) => a as String) .toList(), ); } } class ParsedRecipe { final String name; final String? description; final String? instructions; final List ingredients; const ParsedRecipe({ required this.name, this.description, this.instructions, required this.ingredients, }); factory ParsedRecipe.fromJson(Map json) { final rawIngredients = json['ingredients'] as List? ?? []; return ParsedRecipe( name: json['name'] as String? ?? '', description: json['description'] as String?, instructions: json['instructions'] as String?, ingredients: rawIngredients .map((i) => ParsedIngredient.fromJson(i as Map)) .toList(), ); } }