forked from eatvio/eatvio_app
173 lines
6.3 KiB
Dart
173 lines
6.3 KiB
Dart
import 'package:eatvio_app/features/consultations/models/consultation_model.dart';
|
|
import 'package:eatvio_app/features/diary/entities/diary_day_entity.dart';
|
|
import 'package:eatvio_app/features/diary/entities/diary_future_diet_day_entity.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
part 'diary_day_model.freezed.dart';
|
|
|
|
part 'diary_day_model.g.dart';
|
|
|
|
enum PortionState {
|
|
@JsonValue('filled_diet')
|
|
filledDiet,
|
|
@JsonValue('eaten_from_diet')
|
|
eatenFromDiet,
|
|
eaten,
|
|
@JsonValue('eaten_deleted')
|
|
eatenDeleted,
|
|
@JsonValue('eaten_edited')
|
|
eatenEdited,
|
|
commented,
|
|
@JsonValue('commented_from_diet')
|
|
commentedFromDiet,
|
|
@JsonValue('reviewed_by_user')
|
|
reviewedByUser,
|
|
@JsonValue('reviewed_from_diet')
|
|
reviewedFromDiet,
|
|
unknown,
|
|
}
|
|
|
|
@freezed
|
|
abstract class DiaryDayWrapperModel with _$DiaryDayWrapperModel {
|
|
const factory DiaryDayWrapperModel({@JsonKey(name: "diary") required DiaryDayModel diary}) = _DiaryDayWrapperModel;
|
|
|
|
factory DiaryDayWrapperModel.fromJson(Map<String, dynamic> json) => _$DiaryDayWrapperModelFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class DiaryDayModel with _$DiaryDayModel {
|
|
const factory DiaryDayModel({
|
|
@JsonKey(name: "id") required int? id,
|
|
@JsonKey(name: "date") required String date,
|
|
@JsonKey(name: "wakeup") String? wakeup,
|
|
@JsonKey(name: "retire") String? retire,
|
|
@JsonKey(name: "closed") required int closed,
|
|
@JsonKey(name: "comment") required String comment,
|
|
@JsonKey(name: "state") required TypeOfDiaryModel typeOfDiary,
|
|
@JsonKey(name: "meals") required List<MealModel> meals,
|
|
@JsonKey(name: "chosen_plan_id") required int? chosenPlanId,
|
|
@JsonKey(name: "day_of_chosen_diet") required int? dayOfChosenDiet,
|
|
@JsonKey(name: "chosen_diet", fromJson: parseDiet) required DiaryDietModel? diet,
|
|
}) = _DiaryDayModel;
|
|
const DiaryDayModel._();
|
|
factory DiaryDayModel.fromJson(Map<String, dynamic> json) => _$DiaryDayModelFromJson(json);
|
|
|
|
DiaryDayEntity? toEntity() {
|
|
if (id == null) {
|
|
return null;
|
|
}
|
|
return DiaryDayEntity(
|
|
id: id!,
|
|
date: date,
|
|
closed: closed,
|
|
comment: comment,
|
|
typeOfDiary: typeOfDiary,
|
|
meals: meals,
|
|
chosenPlanId: chosenPlanId,
|
|
dayOfChosenDiet: dayOfChosenDiet,
|
|
wakeup: wakeup,
|
|
retire: retire,
|
|
diet: diet,
|
|
);
|
|
}
|
|
|
|
DiaryFutureDietDayEntity toDiaryFutureDayEntity() {
|
|
return DiaryFutureDietDayEntity(date: date, typeOfDiary: typeOfDiary, meals: meals, dayOfChosenDiet: dayOfChosenDiet, diet: diet);
|
|
}
|
|
}
|
|
|
|
DiaryDietModel? parseDiet(dynamic json) {
|
|
if (json == null) return null;
|
|
return DiaryDietModel.fromJson(json['diet']);
|
|
}
|
|
|
|
@freezed
|
|
abstract class DiaryDietModel with _$DiaryDietModel {
|
|
const factory DiaryDietModel({required int id, required int duration, required String name}) = _DiaryDietModel;
|
|
|
|
factory DiaryDietModel.fromJson(Map<String, dynamic> json) => _$DiaryDietModelFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class MealModel with _$MealModel {
|
|
const factory MealModel({
|
|
@JsonKey(name: "id") required int id,
|
|
@JsonKey(name: "time") required String time,
|
|
@JsonKey(name: "type_no") required int typeNumber,
|
|
@JsonKey(name: "satiety") required int satiety,
|
|
@JsonKey(name: "mood") required int mood,
|
|
@JsonKey(name: "portions") required List<PortionModel> portions,
|
|
@JsonKey(name: "photos") required List<DiaryPhotoModel> photos,
|
|
}) = _MealModel;
|
|
|
|
factory MealModel.fromJson(Map<String, dynamic> json) => _$MealModelFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class DiaryPhotoModel with _$DiaryPhotoModel {
|
|
const factory DiaryPhotoModel({
|
|
@JsonKey(name: "id") required int id,
|
|
@JsonKey(name: "original_name") required String originalName,
|
|
@JsonKey(name: "path") required String path,
|
|
@JsonKey(name: "size") required int size,
|
|
}) = _DiaryPhotoModel;
|
|
|
|
factory DiaryPhotoModel.fromJson(Map<String, dynamic> json) => _$DiaryPhotoModelFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class ProductCaloriesInfoModel with _$ProductCaloriesInfoModel {
|
|
const factory ProductCaloriesInfoModel({
|
|
@JsonKey(name: "id") required int id,
|
|
@JsonKey(name: "product_name") required String productName,
|
|
@JsonKey(name: "energy_on_100gr") required double calories,
|
|
@JsonKey(name: "proteins_on_100gr") required double proteins,
|
|
@JsonKey(name: "fats_on_100gr") required double fats,
|
|
@JsonKey(name: "carbohydrates_on_100gr") required double carbohydrates,
|
|
@JsonKey(name: "energy_on_portion") required double energyOnPortion,
|
|
@JsonKey(name: "proteins_on_portion") required double proteinsOnPortion,
|
|
@JsonKey(name: "fats_on_portion") required double fatsOnPortion,
|
|
@JsonKey(name: "carbohydrates_on_portion") required double carbohydratesOnPortion,
|
|
}) = _ProductCaloriesInfoModel;
|
|
|
|
factory ProductCaloriesInfoModel.fromJson(Map<String, dynamic> json) => _$ProductCaloriesInfoModelFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class PortionModel with _$PortionModel {
|
|
const factory PortionModel({
|
|
@JsonKey(name: "id") required int id,
|
|
@JsonKey(name: "product_nutritional_value_id") int? productNutritionalValueId,
|
|
ProductCaloriesInfoModel? productCaloriesInfo,
|
|
@JsonKey(name: "product_name") required String productName,
|
|
@JsonKey(name: "quantity") required int quantity,
|
|
@JsonKey(name: "portion") required String portion,
|
|
@JsonKey(name: "from_diet") required bool fromDiet,
|
|
@JsonKey(name: "state", unknownEnumValue: PortionState.unknown) required PortionState portionState,
|
|
}) = _PortionModel;
|
|
|
|
factory PortionModel.fromJson(Map<String, dynamic> json) => _$PortionModelFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class TypeOfDiaryModel with _$TypeOfDiaryModel {
|
|
const factory TypeOfDiaryModel({
|
|
@JsonKey(name: "has_chosen_diet") required bool hasChosenDiet,
|
|
@JsonKey(name: "has_chosen_plan") required bool hasChosenPlan,
|
|
@JsonKey(name: "last_state") required DiaryStateEnum? diaryState,
|
|
}) = _TypeOfDiaryModel;
|
|
|
|
factory TypeOfDiaryModel.fromJson(Map<String, dynamic> json) => _$TypeOfDiaryModelFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class ProductInMeal with _$ProductInMeal {
|
|
const factory ProductInMeal({
|
|
@JsonKey(name: 'product_name') required String productName,
|
|
@JsonKey(name: 'portion') required String portion,
|
|
@JsonKey(name: 'quantity') required int quantity,
|
|
}) = _ProductInMeal;
|
|
|
|
factory ProductInMeal.fromJson(Map<String, Object?> json) => _$ProductInMealFromJson(json);
|
|
}
|