import 'package:shared_preferences/shared_preferences.dart';

class SharedPreferencesUtil {
  static SharedPreferencesUtil? _instance;
  static SharedPreferences? _sharedPreferences;

  static const String keyAccessToken = "accessToken";
  static const String keyWebRefreshToken = "XSRF-TOKEN";
  static const String keyWebAccessToken = "duo_ip_mart_session";
  static const String keyUserId = "user_id";
  static const String keyNotificationCount = "notification_count";
  static const String keyListCount = "list_count";

  static Future<SharedPreferencesUtil> getInstance() async {
    _instance ??= SharedPreferencesUtil();
    _sharedPreferences ??= await SharedPreferences.getInstance();
    return _instance ?? SharedPreferencesUtil();
  }

  String? getString(String key) => _sharedPreferences!.getString(key);

  Future<bool> putString(String key, String value) async =>
      await _sharedPreferences!.setString(key, value);

  int? getInt(String key) => _sharedPreferences!.getInt(key);

  Future<bool> putInt(String key, int value) async =>
      await _sharedPreferences!.setInt(key, value);

  bool? getBool(String key) => _sharedPreferences!.getBool(key);

  Future<bool> putBool(String key, bool value) =>
      _sharedPreferences!.setBool(key, value);

  removeString(String key) async {
    await _sharedPreferences?.remove(key);
  }

  removeAll() async {
    await _sharedPreferences?.remove(keyAccessToken);
    await _sharedPreferences?.remove(keyWebRefreshToken);
    await _sharedPreferences?.remove(keyWebAccessToken);
    await _sharedPreferences?.remove(keyUserId);
    await _sharedPreferences?.remove(keyNotificationCount);
    await _sharedPreferences?.remove(keyListCount);
  }
}
