import 'package:mc_common_app/extensions/string_extensions.dart'; import 'package:mc_common_app/models/services/item_model.dart'; import 'package:mc_common_app/models/widgets_models.dart'; class ServiceAppointmentScheduleModel { List? serviceSlotList; List? serviceItemList; String? selectedDate; String? selectedTimeSlot; List? availableDates; List? availableTimeSlots; double? amountToPay; double? amountTotal; double? amountRem; ServiceAppointmentScheduleModel({ this.serviceSlotList, this.serviceItemList, this.selectedDate, this.selectedTimeSlot, this.availableDates, this.availableTimeSlots, this.amountToPay, this.amountTotal, this.amountRem, }); List getFormattedSlotTimes() { var seenSlots = {}; var slotTimeData = serviceSlotList! .where((slot) => seenSlots.add(TimeSlotModel( slot: slot.startTime!, slotId: slot.id!, isSelected: false, ))) .toList(); List slotTime = []; for (var element in slotTimeData) { slotTime.add(TimeSlotModel(isSelected: false, slotId: element.id!, slot: element.slotDate ?? "")); } return slotTime; } List getFormattedSlotDates() { var seenDates = {}; var slotDatesData = serviceSlotList! .where((slot) => seenDates.add(TimeSlotModel( slot: slot.slotDate!, slotId: slot.id!, isSelected: false, ))) .toList(); List slotDates = []; for (var element in slotDatesData) { slotDates.add(TimeSlotModel(isSelected: false, slotId: element.id!, slot: element.slotDate!.toFormattedDateWithoutTime() ?? "")); } return slotDates; } //TODO: I WILL START FROM HERE; I NEED TO ONLY PICK THE DISTINCT DATES FROM THE RESPONSE AND THEN BASED ON THE DATE SELECTION I WILL PICK THEIR SLOTS. //TODO: AFTER THAT, I WILL ServiceAppointmentScheduleModel.fromJson(Map json) { if (json['serviceSlotList'] != null) { serviceSlotList = []; json['serviceSlotList'].forEach((v) { serviceSlotList!.add(ServiceSlotList.fromJson(v)); }); } if (json['serviceItemList'] != null) { serviceItemList = []; json['serviceItemList'].forEach((v) { serviceItemList!.add(ItemData.fromJson(v)); }); } amountToPay = json['amountToPay']; selectedDate = ''; selectedTimeSlot = ''; availableDates = getFormattedSlotDates(); availableTimeSlots = getFormattedSlotTimes(); amountTotal = json['amountTotal']; amountRem = json['amountRem']; } Map toJson() { final Map data = {}; if (serviceSlotList != null) { data['serviceSlotList'] = serviceSlotList!.map((v) => v.toJson()).toList(); } if (serviceItemList != null) { data['serviceItemList'] = serviceItemList!.map((v) => v.toJson()).toList(); } data['amountToPay'] = amountToPay; data['amountTotal'] = amountTotal; data['amountRem'] = amountRem; return data; } } class ServiceSlotList { int? id; int? branchAppointmentScheduleID; String? branchAppointmentSchedule; int? serviceProviderID; String? slotDate; String? startTime; String? endTime; int? bookAppointment; int? allowAppointment; int? slotDurationMinute; int? appointmentType; bool? isActive; int? createdBy; String? createdOn; int? modifiedBy; String? modifiedOn; ServiceSlotList( {this.id, this.branchAppointmentScheduleID, this.branchAppointmentSchedule, this.serviceProviderID, this.slotDate, this.startTime, this.endTime, this.bookAppointment, this.allowAppointment, this.slotDurationMinute, this.appointmentType, this.isActive, this.createdBy, this.createdOn, this.modifiedBy, this.modifiedOn}); ServiceSlotList.fromJson(Map json) { id = json['id']; branchAppointmentScheduleID = json['branchAppointmentScheduleID']; branchAppointmentSchedule = json['branchAppointmentSchedule']; serviceProviderID = json['serviceProviderID']; slotDate = json['slotDate']; startTime = json['startTime']; endTime = json['endTime']; bookAppointment = json['bookAppointment']; allowAppointment = json['allowAppointment']; slotDurationMinute = json['slotDurationMinute']; appointmentType = json['appointmentType']; isActive = json['isActive']; createdBy = json['createdBy']; createdOn = json['createdOn']; modifiedBy = json['modifiedBy']; modifiedOn = json['modifiedOn']; } Map toJson() { final Map data = {}; data['id'] = id; data['branchAppointmentScheduleID'] = branchAppointmentScheduleID; data['branchAppointmentSchedule'] = branchAppointmentSchedule; data['serviceProviderID'] = serviceProviderID; data['slotDate'] = slotDate; data['startTime'] = startTime; data['endTime'] = endTime; data['bookAppointment'] = bookAppointment; data['allowAppointment'] = allowAppointment; data['slotDurationMinute'] = slotDurationMinute; data['appointmentType'] = appointmentType; data['isActive'] = isActive; data['createdBy'] = createdBy; data['createdOn'] = createdOn; data['modifiedBy'] = modifiedBy; data['modifiedOn'] = modifiedOn; return data; } }