import 'package:aitrainer_app/model/result.dart'; import 'package:intl/intl.dart'; class ExerciseResult { late int? exerciseResultId; late int customerId; late int exerciseId; late int exercisePlanId; late String resultType; late double value; late DateTime dateFrom; late DateTime? dateTo; ResultExt? resultExtension; ExerciseResult(); Map toJson() { String? formattedDateTo; if (dateTo != null) { formattedDateTo = DateFormat('yyyy-MM-dd HH:mm').format(dateTo!); } return { "customerId": customerId, "exerciseId": exerciseId, "exercisePlanId": exercisePlanId, "resultType": resultType, "value": value, "dateFrom": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateFrom), "dateTo": formattedDateTo, }; } ExerciseResult.fromJson(Map json) { this.exerciseResultId = json['exerciseResultId']; this.exerciseId = json['exerciseId']; this.exercisePlanId = json['exercisePlanId']; this.customerId = json['customerId']; this.resultType = json['resultType']; this.value = json["value"]; this.dateFrom = DateTime.parse(json['dateFrom']); this.dateTo = DateTime.parse(json['dateTo']); this.resultExtension = ResultExt(itemString: this.resultType); } }