import 'dart:collection'; import 'package:intl/intl.dart'; import 'package:workouttest_util/model/customer_membership.dart'; import 'customer_property.dart'; class Customer { String? name; String? email; String? firstname; String? sex; int? age; String? active; int? customerId; String? password; int? birthYear; String? goal; String? fitnessLevel; String? bodyType; int? admin; int? trainer; int? dataPolicyAllowed; String? firebaseUid; DateTime? dateAdd; DateTime? dateChange; int? emailSubscription; int? sportId; DateTime? syncedDate; DateTime? trialDate; String? firebaseRegToken; String? lang; int? lifeLong; LinkedHashMap properties = LinkedHashMap(); List customerProperties = []; List memberships = []; Customer( {customerId, name, firstname, email, sex, age, active, password, birthYear, bodyType, fitnessLevel, goal, admin, trainer, dataPolicyAllowed, firebaseUid, dateAdd, dateChange}) { dateAdd = DateTime.now(); dateChange = DateTime.now(); } Customer.fromJson(Map json) { customerId = json['customerId']; name = json['name']; firstname = json['firstname']; email = json['email']; sex = json['sex']; age = json['age']; active = json['active']; birthYear = json['birthYear']; bodyType = json['bodyType']; fitnessLevel = json['fitnessLevel']; goal = json['goal']; admin = json['admin']; lifeLong = json['lifeLong']; trainer = json['trainer']; firebaseUid = json['firebaseUid']; firebaseRegToken = json['firebaseRegToken']; lang = json['lang']; dataPolicyAllowed = json['dataPolicyAllowed']; emailSubscription = json['emailSubscription']; sportId = json['sportId']; syncedDate = json['syncedDate'] == null ? null : DateTime.parse(json['syncedDate']); trialDate = json['trialDate'] == null ? null : DateTime.parse(json['trialDate']); dateAdd = json['dateAdd'] == null ? DateTime.parse("0000-00-00") : DateTime.parse(json['dateAdd']); dateChange = json['dateChange'] == null ? DateTime.parse("0000-00-00") : DateTime.parse(json['dateChange']); if (json['properties'] != null && json['properties'].length > 0) { customerProperties = json['properties'].map((detail) => CustomerProperty.fromJson(detail)).toList(); } if (json['memberships'] != null && json['memberships'].length > 0) { memberships = json['memberships'].map((detail) => CustomerMembership.fromJson(detail)).toList(); } } Map toJson() => { "name": name, "firstname": firstname, "email": email, "age": age, "sex": sex, "active": 'Y', "password": password, "birthYear": birthYear, "bodyType": bodyType, "fitnessLevel": fitnessLevel, "goal": goal, "admin": admin, "trainer": trainer, "dataPolicyAllowed": dataPolicyAllowed, "dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd!), "dateChange": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateChange!), "emailSubscription": emailSubscription, "sportId": sportId, "syncedDate": syncedDate == null ? null : DateFormat('yyyy-MM-dd HH:mm:ss').format(syncedDate!), "trialDate": trialDate == null ? null : DateFormat('yyyy-MM-dd HH:mm:ss').format(trialDate!), "firebaseRegToken": firebaseRegToken, "lang": lang, "lifeLong": lifeLong, }; @override String toString() => toJson().toString(); double getProperty(String propertyName) { if (properties[propertyName] == null) { return 0; } else { return properties[propertyName]!.propertyValue; } } String getPropertyDate(String propertyName) { if (properties[propertyName] == null) { return ""; } else { if (properties[propertyName]!.dateAdd == null) { return ""; } else { return DateFormat('yyyy-MM-dd').format(properties[propertyName]!.dateAdd!); } } } setProperty(String propertyName, double value) { properties[propertyName]!.propertyValue = value; } }