class DiaryEntry { final String id; final String date; final String mealType; final String name; final double portions; final double? calories; final double? proteinG; final double? fatG; final double? carbsG; final String source; final String? dishId; final String? recipeId; final double? portionG; const DiaryEntry({ required this.id, required this.date, required this.mealType, required this.name, required this.portions, this.calories, this.proteinG, this.fatG, this.carbsG, required this.source, this.dishId, this.recipeId, this.portionG, }); factory DiaryEntry.fromJson(Map json) { return DiaryEntry( id: json['id'] as String? ?? '', date: json['date'] as String? ?? '', mealType: json['meal_type'] as String? ?? '', name: json['name'] as String? ?? '', portions: (json['portions'] as num?)?.toDouble() ?? 1, calories: (json['calories'] as num?)?.toDouble(), proteinG: (json['protein_g'] as num?)?.toDouble(), fatG: (json['fat_g'] as num?)?.toDouble(), carbsG: (json['carbs_g'] as num?)?.toDouble(), source: json['source'] as String? ?? 'manual', dishId: json['dish_id'] as String?, recipeId: json['recipe_id'] as String?, portionG: (json['portion_g'] as num?)?.toDouble(), ); } String get mealLabel { switch (mealType) { case 'breakfast': return 'Завтрак'; case 'lunch': return 'Обед'; case 'dinner': return 'Ужин'; default: return mealType; } } }