import 'recipe.dart'; class MenuPlan { final String id; final String weekStart; final List days; const MenuPlan({ required this.id, required this.weekStart, required this.days, }); factory MenuPlan.fromJson(Map json) { return MenuPlan( id: json['id'] as String? ?? '', weekStart: json['week_start'] as String? ?? '', days: (json['days'] as List? ?? []) .map((e) => MenuDay.fromJson(e as Map)) .toList(), ); } } class MenuDay { final int day; final String date; final List meals; final double totalCalories; const MenuDay({ required this.day, required this.date, required this.meals, required this.totalCalories, }); factory MenuDay.fromJson(Map json) { return MenuDay( day: json['day'] as int? ?? 0, date: json['date'] as String? ?? '', meals: (json['meals'] as List? ?? []) .map((e) => MealSlot.fromJson(e as Map)) .toList(), totalCalories: (json['total_calories'] as num?)?.toDouble() ?? 0, ); } // Localized day name. String get dayName { const names = [ 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье', ]; final i = day - 1; return (i >= 0 && i < names.length) ? names[i] : 'День $day'; } // Short date label like "16 фев". String get shortDate { try { final dt = DateTime.parse(date); const months = [ 'янв', 'фев', 'мар', 'апр', 'май', 'июн', 'июл', 'авг', 'сен', 'окт', 'ноя', 'дек', ]; return '${dt.day} ${months[dt.month - 1]}'; } catch (_) { return date; } } } class MealSlot { final String id; final String mealType; final MenuRecipe? recipe; const MealSlot({ required this.id, required this.mealType, this.recipe, }); factory MealSlot.fromJson(Map json) { return MealSlot( id: json['id'] as String? ?? '', mealType: json['meal_type'] as String? ?? '', recipe: json['recipe'] != null ? MenuRecipe.fromJson(json['recipe'] as Map) : null, ); } String get mealLabel { switch (mealType) { case 'breakfast': return 'Завтрак'; case 'lunch': return 'Обед'; case 'dinner': return 'Ужин'; default: return mealType; } } String get mealEmoji { switch (mealType) { case 'breakfast': return '🌅'; case 'lunch': return '☀️'; case 'dinner': return '🌙'; default: return '🍽️'; } } } class MenuRecipe { final String id; final String title; final String imageUrl; final NutritionInfo? nutrition; const MenuRecipe({ required this.id, required this.title, required this.imageUrl, this.nutrition, }); factory MenuRecipe.fromJson(Map json) { return MenuRecipe( id: json['id'] as String? ?? '', title: json['title'] as String? ?? '', imageUrl: json['image_url'] as String? ?? '', nutrition: json['nutrition_per_serving'] != null ? NutritionInfo.fromJson( json['nutrition_per_serving'] as Map) : null, ); } }