///todo deleted
// import 'dart:convert';
//
// import 'package:flutter/cupertino.dart';
// import 'package:http/http.dart';
// import 'package:test_sa/controllers/api_routes/api_manager.dart';
// import 'package:test_sa/controllers/api_routes/urls.dart';
// import 'package:test_sa/models/user.dart';
// import 'package:test_sa/models/visits/ppm.dart';
// import 'package:test_sa/models/visits/ppm_search.dart';
// import 'package:test_sa/models/visits/visits_group.dart';
//
// class PreventiveMaintenanceVisitsProvider extends ChangeNotifier {
//   // number of items call in each request
//   final pageItemNumber = 10;
//
//   //reset provider data
//   void reset() {
//     visits = null;
//     nextPage = true;
//     stateCode = null;
//   }
//
//   // state code of current request to defied error message
//   // like 400 customer request failed
//   // 500 service not available
//   int stateCode;
//
//   // true if there is next page in product list and false if not
//   bool nextPage = true;
//
//   // list of user requests
//   List<Visit> visits;
//
//   // when requests in-process _loading = true
//   // done _loading = true
//   // failed _loading = false
//   bool isLoading;
//
//   VisitsSearch visitsSearch = VisitsSearch();
//
//   /// return -2 if request in progress
//   /// return -1 if error happen when sending request
//   /// return state code if request complete may be 200, 404 or 403
//   /// for more details check http state manager
//   /// lib\controllers\http_status_manger\http_status_manger.dart
//   Future<int> getVisits({
//     required String host,
//     required User user,
//     // VisitsSearch visitsSearch,
//   }) async {
//     if (isLoading == true) return -2;
//     isLoading = true;
//     Response response;
//     //userId = 397.toString(); // testing id to view data
//     try {
//       response = await get(
//           Uri.parse(
//             "${host + URLs.getPreventiveMaintenanceVisits}?uid=${user.id}&token=${user.token}&page=${(visits?.length ?? 0) ~/ pageItemNumber}${visitsSearch?.toMap()}",
//           ),
//           headers: {"Content-Type": "application/json; charset=utf-8"});
//     } catch (error) {
//       isLoading = false;
//       stateCode = -1;
//       notifyListeners();
//       return -1;
//     }
//     stateCode = response.statusCode;
//     if (response.statusCode >= 200 && response.statusCode < 300) {
//       // client's request was successfully received
//       List requestsListJson = json.decode(utf8.decode(response.bodyBytes));
//       List<Visit> _visits = requestsListJson.map((request) => Visit.fromJson(request)).toList();
//       visits ??= [];
//       visits.addAll(_visits);
//       if (_visits.length == pageItemNumber) {
//         nextPage = true;
//       } else {
//         nextPage = false;
//       }
//     }
//     isLoading = false;
//     notifyListeners();
//     return response.statusCode;
//   }
//
//   /// return -2 if request in progress
//   /// return -1 if error happen when sending request
//   /// return state code if request complete may be 200, 404 or 403
//   /// for more details check http state manager
//   /// lib\controllers\http_status_manger\http_status_manger.dart
//   Future<int> updateGroupOfVisits({
//     required String host,
//     required User user,
//     VisitsGroup group,
//   }) async {
//     Response response;
//     Map<String, String> body = group.toJson();
//     // body["token"] = user.token ?? "";
//     // body["uid"] = user.id;
//     //userId = 397.toString(); // testing id to view data
//     try {
//       response = await ApiManager.instance.put(URLs.updatePreventiveMaintenanceVisits, body: body);
//
//       stateCode = response.statusCode;
//       if (response.statusCode >= 200 && response.statusCode < 300) {
//         // client's request was successfully received
//         // group.visits.forEach((visit) {
//         //   visit.status = group.status;
//         //   visit.actualDate = group.date.toString().split(" ").first;
//         // });
//         group.ppms.clear();
//         notifyListeners();
//       }
//
//       return response.statusCode;
//     } catch (error) {
//       isLoading = false;
//       stateCode = -1;
//       notifyListeners();
//       return -1;
//     }
//   }
// }
