import 'package:car_customer_app/repositories/provider_repo.dart'; import 'package:mc_common_app/classes/consts.dart'; import 'package:mc_common_app/models/appointments_models/appointment_list_model.dart'; import 'package:mc_common_app/models/branch_models/branch_detail_model.dart'; import 'package:mc_common_app/models/provider_category_model.dart'; import 'package:mc_common_app/models/widgets_models.dart'; import 'package:mc_common_app/repositories/common_repo.dart'; import 'package:mc_common_app/services/common_services.dart'; import 'package:mc_common_app/utils/enums.dart'; import 'package:mc_common_app/view_models/base_view_model.dart'; import 'package:mc_common_app/models/services/item_model.dart'; class AppointmentsVM extends BaseVM { final CommonRepo commonRepo; final BranchRepo branchRepo; final CommonAppServices commonServices; AppointmentsVM({required this.commonServices, required this.branchRepo, required this.commonRepo}); List providersFilterOptions = []; List nearbyBranchesList = []; ItemModel? serviceItems; ProviderModel? providerModel; populateProvidersFilterList() { providersFilterOptions.clear(); providersFilterOptions = [ FilterListModel(title: "All Branches", isSelected: true, id: -1), FilterListModel(title: "Maintenance", isSelected: false, id: 0), FilterListModel(title: "Oil Service", isSelected: false, id: 1), FilterListModel(title: "Accessories", isSelected: false, id: 2), FilterListModel(title: "Tire Service", isSelected: false, id: 3), FilterListModel(title: "Dent and Paint", isSelected: false, id: 4), ]; notifyListeners(); } applyFilterOnProviders({required int index}) { if (providersFilterOptions.isEmpty) return; for (var value in providersFilterOptions) { value.isSelected = false; } providersFilterOptions[index].isSelected = true; notifyListeners(); } //Create new branch getAllNearBranches({bool isNeedToRebuild = false}) async { //TODO: needs to lat,long into API nearbyBranchesList.clear(); if (isNeedToRebuild) setState(ViewState.busy); nearbyBranchesList = await branchRepo.getAllNearBranchAndServices(); setState(ViewState.idle); } Future getServiceItems(int serviceId) async { serviceItems = null; serviceItems = await branchRepo.getServiceItems(serviceId); setState(ViewState.idle); return serviceItems; } getBranchAndServices(int providerId) async { providerModel = null; providerModel = await branchRepo.getBranchAndServices(providerId); setState(ViewState.idle); } bool isFetchingLists = false; List myAppointments = []; List appointmentsFilterOptions = []; bool isFetchingServices = false; List branchCategories = []; bool isHomeTapped = false; void updateIsHomeTapped(bool value) { isHomeTapped = value; notifyListeners(); } String pickedHomeLocation = ""; String pickHomeLocationError = ""; void updatePickedHomeLocation(String value) { pickedHomeLocation = value; pickHomeLocationError = ""; notifyListeners(); } void updatePickHomeLocationError(String value) { pickHomeLocationError = value; notifyListeners(); } SelectionModel providerCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); void updateProviderCategoryId(SelectionModel id) async { providerCategoryId = id; await getBranchServices(id.selectedId); notifyListeners(); } List branchServices = []; SelectionModel branchServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); void updateProviderServiceId(SelectionModel id) async { branchServiceId = id; notifyListeners(); } void getBranchCategories() async { notifyListeners(); branchCategories = await commonRepo.getProviderServiceCategories(); notifyListeners(); } getBranchServices(int categoryId) async { branchServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); isHomeTapped = false; pickedHomeLocation = ""; pickHomeLocationError = ""; if (categoryId != -1) { isFetchingServices = true; notifyListeners(); branchServices = getFilteredBranchServices(categoryId: categoryId, branchId: 6); isFetchingServices = false; notifyListeners(); } } List getFilteredBranchServices({required int branchId, required int categoryId}) { // List filteredServices = nearbyBranchesList.where((element) => element) return []; } bool isServiceSelectionValidated() { if (branchServiceId.selectedId == -1) { return false; } if (isHomeTapped) { if (pickedHomeLocation == "") { updatePickHomeLocationError(GlobalConsts.homeLocationEmptyError); return false; } } return true; } populateAppointmentsFilterList() { appointmentsFilterOptions.clear(); appointmentsFilterOptions = [ FilterListModel(title: "All Appointments", isSelected: true, id: -1), FilterListModel(title: "Booked", isSelected: false, id: 1), FilterListModel(title: "Confirmed", isSelected: false, id: 2), FilterListModel(title: "Arrived", isSelected: false, id: 3), FilterListModel(title: "Cancelled", isSelected: false, id: 4), ]; notifyListeners(); } applyFilterOnAppointmentsVM({required int index}) { if (appointmentsFilterOptions.isEmpty) return; for (var value in appointmentsFilterOptions) { value.isSelected = false; } appointmentsFilterOptions[index].isSelected = true; notifyListeners(); } Future getMyAppointments() async { isFetchingLists = true; myAppointments = await commonRepo.getMyAppointments(); isFetchingLists = false; notifyListeners(); } }