import 'dart:convert'; import 'package:flutter/cupertino.dart'; import 'package:syncrow_web/pages/access_management/model/password_model.dart'; import 'package:syncrow_web/pages/visitor_password/model/schedule_model.dart'; import 'package:syncrow_web/services/api/http_service.dart'; import 'package:syncrow_web/utils/constants/api_const.dart'; import '../pages/visitor_password/model/device_model.dart'; class AccessMangApi{ Future> fetchVisitorPassword() async { try { final response = await HTTPService().get( path: ApiEndpoints.visitorPassword, showServerMessage: true, expectedResponseModel: (json) { List jsonData = json; print('Password List: $json'); List passwordList = jsonData.map((jsonItem) { return PasswordModel.fromJson(jsonItem); }).toList(); return passwordList; }, ); return response; } catch (e) { debugPrint('Error fetching visitor passwords: $e'); return []; } } Future fetchDevices() async { try { final response = await HTTPService().get( path: ApiEndpoints.getDevices, showServerMessage: true, expectedResponseModel: (json) { List jsonData = json; print('fetchDevices List: $json'); List passwordList = jsonData.map((jsonItem) { return DeviceModel.fromJson(jsonItem); }).toList(); return passwordList; }, ); return response; } catch (e) { debugPrint('Error fetching $e'); return []; } } Future postOnlineOneTime({String? email,String? passwordName,List? devicesUuid}) async { try { print('postOfflineOneTime List: ${ { "email": email, "passwordName": passwordName, "devicesUuid": devicesUuid } }'); final response = await HTTPService().post( path: ApiEndpoints.sendOnlineOneTime, body: jsonEncode({ "email": email, "passwordName": passwordName, "devicesUuid": devicesUuid }), showServerMessage: true, expectedResponseModel: (json) { List jsonData = json; print('postOfflineOneTime List: $json'); }, ); return response; } catch (e) { debugPrint('Error fetching $e'); return []; } } Future postOnlineMultipleTime({ String? effectiveTime, String? invalidTime, String? email, String? password, String? passwordName, List? scheduleList, List? devicesUuid}) async { try { Map body = { "email": email, "devicesUuid": devicesUuid, "passwordName": passwordName, "password": password, "effectiveTime": effectiveTime, "invalidTime": invalidTime, }; print('createPassword =${scheduleList![0].workingDay}'); if (scheduleList != null) { body["scheduleList"] = scheduleList.map((schedule) => schedule.toJson()).toList(); } print('createPassword =$body'); final response = await HTTPService().post( path: ApiEndpoints.sendOnlineMultipleTime, body: jsonEncode(body), showServerMessage: true, expectedResponseModel: (json) { List jsonData = json; print('postOfflineOneTime List: $json'); }, ); return response; } catch (e) { debugPrint('Error fetching $e'); return []; } } // OffLine One Time Password Future postOffLineOneTime({String? email,String? passwordName,List? devicesUuid}) async { try { print('postOfflineOneTime List: ${ { "email": email, "passwordName": passwordName, "devicesUuid": devicesUuid } }'); final response = await HTTPService().post( path: ApiEndpoints.sendOffLineOneTime, body: jsonEncode({ "email": email, "passwordName": passwordName, "devicesUuid": devicesUuid }), showServerMessage: true, expectedResponseModel: (json) { List jsonData = json; print('postOfflineOneTime List: $json'); }, ); return response; } catch (e) { debugPrint('Error fetching $e'); return []; } } Future postOffLineMultipleTime({ String? email, String? passwordName, String? effectiveTime, String? invalidTime, List? devicesUuid }) async { try { print('postOfflineOneTime List: ${ { "email": email, "passwordName": passwordName, "devicesUuid": devicesUuid } }'); final response = await HTTPService().post( path: ApiEndpoints.sendOffLineOneTime, body: jsonEncode({ "email": email, "devicesUuid":devicesUuid, "passwordName": passwordName, "effectiveTime": effectiveTime, "invalidTime": invalidTime }), showServerMessage: true, expectedResponseModel: (json) { List jsonData = json; print('postOfflineOneTime List: $json'); }, ); return response; } catch (e) { debugPrint('Error fetching $e'); return []; } } }