import 'package:intl/intl.dart'; class ExercisePlan { int? exercisePlanId; late int customerId; late String name; String? description; late bool private; late DateTime? dateAdd; late DateTime dateUpd; String? type; int? exercisePlanTemplateId; ExercisePlan(String name, int customerId) { customerId = customerId; name = name; dateUpd = DateTime.now(); } ExercisePlan.fromJson(Map json) { exercisePlanId = json['exercisePlanId']; customerId = json['customerId']; name = json['name']; private = json['private']; description = json['description']; dateAdd = (json['dateAdd'] == null ? null : DateTime.parse(json['dateAdd']))!; dateUpd = (json['dateUpd'] == null ? null : DateTime.parse(json['dateUpd']))!; type = json['type']; exercisePlanTemplateId = json['exercisePlanTemplateId']; } Map toJson() { String? formattedDateAdd; if (dateAdd != null) { formattedDateAdd = DateFormat('yyyy-MM-dd HH:mm').format(dateAdd!); } String formattedDateUpd = DateFormat('yyyy-MM-dd HH:mm').format(dateUpd); if (exercisePlanId == null) { return { "customerId": customerId, "name": name, "description": description, "private": private, "dateAdd": formattedDateAdd, "dateUpd": formattedDateUpd, "type": type, "exercisePlanTemplateId": exercisePlanTemplateId }; } else { return { "exercisePlanId": exercisePlanId, "customerId": customerId, "name": name, "description": description, "private": private, "dateAdd": formattedDateAdd, "dateUpd": formattedDateUpd, "type": type, "exercisePlanTemplateId": exercisePlanTemplateId }; } } @override String toString() { Map json = toJson(); return json.toString(); } }