import 'package:json_annotation/json_annotation.dart'; part 'recipe.g.dart'; @JsonSerializable(explicitToJson: true) class Recipe { final String title; final String description; final String cuisine; final String difficulty; @JsonKey(name: 'prep_time_min') final int prepTimeMin; @JsonKey(name: 'cook_time_min') final int cookTimeMin; final int servings; @JsonKey(name: 'image_url', defaultValue: '') final String imageUrl; @JsonKey(name: 'image_query', defaultValue: '') final String imageQuery; @JsonKey(defaultValue: []) final List ingredients; @JsonKey(defaultValue: []) final List steps; @JsonKey(defaultValue: []) final List tags; @JsonKey(name: 'nutrition_per_serving') final NutritionInfo? nutrition; const Recipe({ required this.title, required this.description, required this.cuisine, required this.difficulty, required this.prepTimeMin, required this.cookTimeMin, required this.servings, this.imageUrl = '', this.imageQuery = '', this.ingredients = const [], this.steps = const [], this.tags = const [], this.nutrition, }); factory Recipe.fromJson(Map json) => _$RecipeFromJson(json); Map toJson() => _$RecipeToJson(this); } @JsonSerializable() class RecipeIngredient { final String name; final double amount; final String unit; const RecipeIngredient({ required this.name, required this.amount, required this.unit, }); factory RecipeIngredient.fromJson(Map json) => _$RecipeIngredientFromJson(json); Map toJson() => _$RecipeIngredientToJson(this); } @JsonSerializable() class RecipeStep { final int number; final String description; @JsonKey(name: 'timer_seconds') final int? timerSeconds; const RecipeStep({ required this.number, required this.description, this.timerSeconds, }); factory RecipeStep.fromJson(Map json) => _$RecipeStepFromJson(json); Map toJson() => _$RecipeStepToJson(this); } @JsonSerializable() class NutritionInfo { final double calories; @JsonKey(name: 'protein_g') final double proteinG; @JsonKey(name: 'fat_g') final double fatG; @JsonKey(name: 'carbs_g') final double carbsG; @JsonKey(defaultValue: true) final bool approximate; const NutritionInfo({ required this.calories, required this.proteinG, required this.fatG, required this.carbsG, this.approximate = true, }); factory NutritionInfo.fromJson(Map json) => _$NutritionInfoFromJson(json); Map toJson() => _$NutritionInfoToJson(this); }