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 Meals { int? id; String? time; int? type; int? satiety; int? mood; List? portions; List? photos; Meals({this.id, this.time, this.type, this.satiety, this.mood, this.portions, this.photos}); Meals.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 Portions.fromJson(v)); }); } if (json['photos'] != null) { json['photos'].forEach((v) { photos.add(new Photos.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 Portions { int? id; String? productName; int? quantity; String? portion; Portions({this.id, this.productName, this.quantity, this.portion}); Portions.fromJson(Map json) { id = json['id']; productName = json['product_name']; quantity = json['quantity']; portion = json['portion']; } 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 Photos { int? id; String? originalName; String? path; int? size; Photos({this.id, this.originalName, this.path, this.size}); Photos.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; } }