import 'package:hive/hive.dart'; import 'package:tmail_ui_user/features/caching/config/hive_cache_client.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/recent_search_cache.dart'; class RecentSearchCacheClient extends HiveCacheClient { @override String get tableName => 'RecentSearchCache'; @override Future clearAllData() { return Future.sync(() async { final boxState = await openBox(); boxState.clear(); }).catchError((error) { throw error; }); } @override Future deleteItem(String key) { return Future.sync(() async { final boxState = await openBox(); return boxState.delete(key); }).catchError((error) { throw error; }); } @override Future deleteMultipleItem(List listKey) { return Future.sync(() async { final boxEmail = await openBox(); return boxEmail.deleteAll(listKey); }).catchError((error) { throw error; }); } @override Future> getAll() { return Future.sync(() async { final boxState = await openBox(); return boxState.values.toList(); }).catchError((error) { throw error; }); } @override Future getItem(String key) { throw UnimplementedError(); } @override Future insertItem(String key, RecentSearchCache newObject) { return Future.sync(() async { final boxState = await openBox(); boxState.put(key, newObject); }).catchError((error) { throw error; }); } @override Future insertMultipleItem(Map mapObject) { throw UnimplementedError(); } @override Future isExistItem(String key) { return Future.sync(() async { final boxState = await openBox(); return boxState.containsKey(key); }).catchError((error) { throw error; }); } @override Future isExistTable() { return Future.sync(() async { return await Hive.boxExists(tableName); }).catchError((error) { throw error; }); } @override Future> openBox() { return Future.sync(() async { if (Hive.isBoxOpen(tableName)) { return Hive.box(tableName); } return await Hive.openBox(tableName); }).catchError((error) { throw error; }); } @override Future updateItem(String key, RecentSearchCache newObject) { return Future.sync(() async { final boxState = await openBox(); boxState.put(key, newObject); }).catchError((error) { throw error; }); } @override Future updateMultipleItem(Map mapObject) { throw UnimplementedError(); } }