import 'package:freezed_annotation/freezed_annotation.dart'; part 'diary_model.freezed.dart'; part 'diary_model.g.dart'; @freezed class DiaryModel with _$DiaryModel { const factory DiaryModel( {required int id, required DateTime date, required DateTime wakeup, required DateTime retire, required int closed, required String comment, required List meals}) = _DiaryModel; factory DiaryModel.fromJson(Map json) => _$DiaryModelFromJson(json); } class Meal { late int id; late String time; late int type; late int satiety; late int mood; List? portions; List? photos; Meal( {required this.id, required this.time, required this.type, required this.satiety, required this.mood, this.portions, this.photos}); Meal.fromJson(Map json) { List portions = []; List photos = []; id = json['id']; time = json['time']; type = json['type']; satiety = json['satiety']; mood = json['mood']; if (json['portions'] != null) { json['portions'].forEach((v) { portions.add(new Portion.fromJson(v)); }); } if (json['photos'] != null) { json['photos'].forEach((v) { photos.add(new Photo.fromJson(v)); }); } } Map toJson() { final Map data = new Map(); data['id'] = this.id; data['time'] = this.time; data['type'] = this.type; data['satiety'] = this.satiety; data['mood'] = this.mood; if (this.portions != null) { data['portions'] = this.portions?.map((v) => v.toJson()).toList(); } if (this.photos != null) { data['photos'] = this.photos?.map((v) => v.toJson()).toList(); } return data; } } class Portion { late int id; late String productName; late int quantity; late String portion; Portion( {required this.id, required this.productName, required this.quantity, required this.portion}); Portion.fromJson(v); Map toJson() { final Map data = new Map(); data['id'] = this.id; data['product_name'] = this.productName; data['quantity'] = this.quantity; data['portion'] = this.portion; return data; } } class Photo { late int id; late String originalName; late String path; late int size; Photo( {required this.id, required this.originalName, required this.path, required this.size}); Photo.fromJson(Map json) { id = json['id']; originalName = json['original_name']; path = json['path']; size = json['size']; } Map toJson() { final Map data = new Map(); data['id'] = this.id; data['original_name'] = this.originalName; data['path'] = this.path; data['size'] = this.size; return data; } }