// import 'package:discover_module/storage_hive/kol_info/kol_info_model_hive.dart'; import 'package:hive_flutter/hive_flutter.dart'; class HiveFunctions { // String userHiveBox="User Box"; // Box which will use to store the things static final _contactbox = Hive.box("mycontact"); static var box1 = Hive.box('checkvalue'); static final apihcpdata = Hive.box("hcpdata"); static final apihcpdata123 = Hive.box('kolshive'); static createUser(Map data) { _contactbox.add(data); } static List getAllUsers11() { final data = _contactbox.keys.map((key) { final value = _contactbox.get(key); print("Checking_Name : $value"); return { "inid": value["inid"], "id": value["id"], "name": value["name"], "org": value["org"], "addr": value["addr"], "phone": value["phone"], "phone_no": value["phone_no"], "email": value["email"], "summarry": value["summarry"], "speciality": value["speciality"], "sub_speciality": value["sub_speciality"], "img_path": value["img_path"] }; }).toList(); return data.reversed.toList(); } static List getAllUsers() { final data = _contactbox.keys.map((key) { final value = _contactbox.get(key); print("Checking_Name : $value"); return { "id": value["id"], "name": value["name"], "org": value["org"], "addr": value["addr"], "phone": value["phone"], "phone_no": value["phone_no"], "email": value["email"], "affiliations_count": value["affiliations_count"], "events_count": value["events_count"], "publications_count": value["publications_count"], "trail_count": value["trail_count"], "summarry": value["summarry"], "license_no": value["license_no"], "p_suffix": value["p_suffix"], "speciality": value["speciality"], "sub_speciality": value["sub_speciality"], "img_path": value["img_path"] }; }).toList(); return data; } static List getindexUsers() { final data = _contactbox.keys.map((key) { final value = _contactbox.get(key); print("Checking_Name : $value"); return { "name": value["name"], "org": value["org"], "adrr": value["adrr"], "phone": value["phone"], "Pphone": value["Pphone"], "email": value["email"], "affno": value["affno"], "eveno": value["eveno"], "pubno": value["pubno"], "trailno": value["trailno"] }; }).toList(); return data.reversed.toList(); } //static deleteUser112(row) {} static deleteUser11(id) async { print("Hive_id: $id"); for (var entry in _contactbox.toMap().entries) { var contactData = entry.value; print("Selected_del_value: $contactData"); if (contactData['id'] == id) { print("entry.keyentry.key: ${entry.key}."); // Found the contact with the matching id await _contactbox.delete(entry.key); // Delete by key print("Record with id $id has been deleted."); return; // Exit the function after deletion } } } static Future deleteUser(int selectedremoveIndic) async { print("storeddelData_id: ${selectedremoveIndic}"); // final userId = "some_user_id"; // Replace with the actual ID you want to query final value = _contactbox.get(selectedremoveIndic - 1); print("ValueeeGet: $value"); if (value == null) { final value1 = _contactbox.get(selectedremoveIndic); print("Valueee11Get: $value1"); print("UniqueId11 : ${value["inid"]}"); } else { final value1 = _contactbox.get(2); print("Valueee11Get: $value1"); print("UniqueId111 : ${value["inid"]}"); } // print(await _contactbox.getAt(selectedremoveIndic)); // int data = selectedremoveIndic; // final storeddelData = _contactbox.get(data); // print("storeddelData_iss: $storeddelData"); // if (storeddelData != null) { // print("I_amNotnull ${storeddelData["id"]}"); // _contactbox.deleteAt(storeddelData["id"]); //} // _hiveBox.delete(dataDel.id); // _contactbox.deleteAt(selectedremoveIndic); // final data = _contactbox.keys.map((_contactbox) { // final value = _contactbox.get(selectedremoveIndic); // print("Del_valuee_is: ${value}"); // }); } // void deleteUser(String userId) { // var _contactbox = Hive.box('contactBox'); // // Find the key corresponding to the userId // for (var key in _contactbox.keys) { // final value = _contactbox.get(key); // if (value["id"] == userId) { // _contactbox.delete(key); // print("Deleted user with id: $userId"); // break; // Exit the loop once the item is deleted // } // } // } // static void deleteUser(int selectedremoveIndic) { // print("I_Am: selectedremoveIndic: ${selectedremoveIndic}"); // // final data = _contactbox.keys.map((key) { // final value = _contactbox.get(selectedremoveIndic); // _contactbox.deleteAt(selectedremoveIndic); // // if (value["id"] == selectedremoveIndic) { // // print("I_Am: selectedremoveIndicnew: ${value["name"]}"); // // } // // }); // } // static addno(int selectedRowId) { // // final box1 = Hive.box("mycontact"); // print("SelectedStoredvaluessss: $selectedRowId"); // box1.add(selectedRowId); // } // static removeno(int selectedRowId) { // // final box1 = Hive.box("mycontact"); // print("SelectedStoredvaluessss: $selectedRowId"); // box1.deleteAt(selectedRowId); // } // static getno() { // // final box1 = Hive.box("mycontact"); // return box1.values; // } static storehcpdata(Map data) { apihcpdata.add(data); } static gethcpdata() { return apihcpdata.values.toList(); } static List getindexUser(String query) { //static getindexUser(String text) async { print("Text_issssssS: $query"); final value = _contactbox.values.toList(); print("Checking_Name_Offline_Searchh : ${value}"); // final offlinesearch1 = value.map((e) => e["name"].toString()).toList(); // print("Checking_offlinesearch1 : ${offlinesearch1}"); List data = value .where((hcp) => hcp['name'].toLowerCase().contains(query.toLowerCase()) || hcp['speciality'].toLowerCase().contains(query.toLowerCase()) || hcp['addr'].toLowerCase().contains(query.toLowerCase())) .toList(); print("Checking_Name_data : ${data}"); // print("Checking_Name : ${value.contains(text)}"); // final dataa = value.get(text); // return { // "name": value["name"], // "org": value["org"], // "adrr": value["adrr"], // "phone": value["phone"], // "Pphone": value["Pphone"], // "email": value["email"], // "affno": value["affno"], // "eveno": value["eveno"], // "pubno": value["pubno"], // "trailno": value["trailno"] // }; // }).toList(); // print("Check_data_is: $data"); return data.toList(); } static getuser(int selectedremoveIndic) { final data = _contactbox.keys.map((selectedremoveIndic) { final value = _contactbox.get(selectedremoveIndic); print("Checking_Name111 : $value"); return { "inid": value["inid"], "id": value["id"], "name": value["name"], "org": value["org"], "addr": value["addr"], "phone": value["phone"], "phone_no": value["phone_no"], "email": value["email"], "summarry": value["summarry"], "speciality": value["speciality"], "sub_speciality": value["sub_speciality"], "img_path": value["img_path"] }; }).toList(); return data; } static getAllhcpdata(String? option) { List myhcpname = _contactbox.values.toList(); if (option == "HCP Name") { return myhcpname.map((e) => e["name"].toString()).toList(); } else { return myhcpname.map((e) => e["speciality"].toString()).toList(); } } static List OfflineStored_getindexUser(String query) { //static getindexUser(String text) async { print("Text_issssssS: $query"); final value = apihcpdata123.values.toList(); print("Checking_Name_Offline_Searchh : ${value}"); // final offlinesearch1 = value.map((e) => e["name"].toString()).toList(); // print("Checking_offlinesearch1 : ${offlinesearch1}"); List data = value .where((hcp) => hcp['name'].toLowerCase().contains(query.toLowerCase()) || // (hcp['speciality'].toLowerCase().contains(query.toLowerCase()) ?? // hcp['spl'].toLowerCase().contains(query.toLowerCase())) || hcp['speciality'].toLowerCase().contains(query.toLowerCase()) || hcp['addr'].toLowerCase().contains(query.toLowerCase())) .toList(); print("Checking_Name_data : ${data}"); // print("Checking_Name : ${value.contains(text)}"); // final dataa = value.get(text); // return { // "name": value["name"], // "org": value["org"], // "adrr": value["adrr"], // "phone": value["phone"], // "Pphone": value["Pphone"], // "email": value["email"], // "affno": value["affno"], // "eveno": value["eveno"], // "pubno": value["pubno"], // "trailno": value["trailno"] // }; // }).toList(); // print("Check_data_is: $data"); return data.toList(); } // static void savemyContact(List selectedIndices, [List displayedHCPList]) async { // print("Iam selectedd $selectedIndices"); // for (int i = 0; i < selectedIndices.length; i++) { // Map? row = await findRecordById1(selectedIndices[i]); // print("StoringgggMyContactneww_isss_isss:Row $row"); // } // } // Map findRecordById(String selectedIndic) { // final list = _contactbox.values.toList(); // } static Map? findRecordById1(String selectedIndic) { final list = _contactbox.values.toList(); return list .firstWhere((element) => element['id'] == int.parse(selectedIndic)); } static savemyContact(Map row) async { print("CheckingRowww ${row!["email"]}"); final value1 = await _contactbox.values.toList(); List value11 = await value1 .where((element) => element["email"] == row["email"]) .toList(); print("Getted_valueee: ${value11}"); if (value11.isEmpty) { print("Getted_valueee_imaEmpty"); Map data = await { "id": row["id"], "name": row["name"], "org": row["org"], "addr": row["addr"], "phone": row["phone"], "phone_no": row["phone_no"], "email": row["email"], "summarry": row["summarry"], "speciality": row["speciality"], "sub_speciality": row["sub_speciality"], "img_path": row["img_path"] }; print("Inserting_data_is: $data"); await _contactbox.put(await getNextAutoIncrementValue(), data); // await _contactbox.add(row); } } static Future getNextAutoIncrementValue() async { var counterBox = await Hive.openBox('counterBox'); if (!counterBox.containsKey('counter')) { counterBox.put('counter', 0); } int? counter = counterBox.get('counter'); counterBox.put('counter', counter! + 1); await counterBox.close(); return counter; } }