import 'dart:io'; import 'package:eatvio_app/features/create_recipe/models/ingredient.dart'; import 'package:eatvio_app/features/create_recipe/models/recipe_model.dart'; import 'package:eatvio_app/features/create_recipe/models/step.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'recipe_create_entity.freezed.dart'; enum TypeOfRecipe { first_meals, second_meals, salads, snacks, sweets, drinks, other; String toString() { switch (this) { case TypeOfRecipe.first_meals: return 'Первые блюда'; case TypeOfRecipe.second_meals: return 'Вторые блюда'; case TypeOfRecipe.salads: return 'Салаты'; case TypeOfRecipe.snacks: return 'Закуски'; case TypeOfRecipe.sweets: return 'Сладости'; case TypeOfRecipe.drinks: return 'Напитки'; case TypeOfRecipe.other: return 'Другое'; } } String toApiType() { switch (this) { case TypeOfRecipe.first_meals: return 'first_meals'; case TypeOfRecipe.second_meals: return 'second_meals'; case TypeOfRecipe.salads: return 'salads'; case TypeOfRecipe.snacks: return 'snacks'; case TypeOfRecipe.sweets: return 'sweets'; case TypeOfRecipe.drinks: return 'drinks'; case TypeOfRecipe.other: return 'other'; } } static TypeOfRecipe? fromString(String value) { switch (value) { case 'Первые блюда': return TypeOfRecipe.first_meals; case 'Вторые блюда': return TypeOfRecipe.second_meals; case 'Салаты': return TypeOfRecipe.salads; case 'Закуски': return TypeOfRecipe.snacks; case 'Сладости': return TypeOfRecipe.sweets; case 'Напитки': return TypeOfRecipe.drinks; case 'Другое': return TypeOfRecipe.other; default: return null; } } } @freezed class RecipeCreateEntity with _$RecipeCreateEntity { const RecipeCreateEntity._(); const factory RecipeCreateEntity({ String? title, TypeOfRecipe? typeOfRecipe, int? countOfPortions, double? energyInOnePortion, int? totalCookHours, int? totalCookMinutes, int? activeCookHours, int? activeCookMinutes, String? description, File? image, String? videoUrl, required List ingredients, required List steps, required List tags, // tags for search }) = _RecipeCreateEntity; RecipeModel toModel() => RecipeModel( title: title, type: typeOfRecipe?.toApiType(), servings: countOfPortions, energyPerServing: energyInOnePortion?.toInt(), totalCookingTime: ((totalCookHours ?? 0) * 60) + (totalCookMinutes ?? 0), activeCookTime: ((activeCookHours ?? 0) * 60) + (activeCookMinutes ?? 0), description: description, image: image?.path, video_url: videoUrl, ingredients: ingredients, steps: steps.map((step) { if (step.hasProps()) return Step(image: step.image?.path ?? '', description: step.description ?? ''); }).toList(), tags: tags, ); } @freezed class StepEntity with _$StepEntity { const StepEntity._(); const factory StepEntity({ String? description, File? image, }) = _StepEntity; bool hasProps() { return description != null; } }