import 'package:shared_preferences/shared_preferences.dart';

class SharedPreferencesHelper {
  static saveStringToSP(String key, String value) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setString(key, value);
  }

  static saveBoolToSP(String key, bool value) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setBool(key, value);
  }

  static saveIntToSP(String key, int value) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setInt(key, value);
  }

  static saveDoubleToSP(String key, double value) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setDouble(key, value);
  }

  static saveStringListToSP(String key, List<String> value) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setStringList(key, value);
  }

  static Future<String> readStringFromSP(String key) async {
    final prefs = await SharedPreferences.getInstance();
    String value = prefs.getString(key) ?? '';
    return value;
  }

  static Future<bool?> readBoolFromSP(String key) async {
    final prefs = await SharedPreferences.getInstance();
    bool? value = prefs.getBool(key);
    return value;
  }

  static Future<int> readIntFromSP(String key) async {
    final prefs = await SharedPreferences.getInstance();
    int value = prefs.getInt(key) ?? 0;
    return value;
  }

  static Future<List<String>> readStringListFromSP(String key) async {
    final prefs = await SharedPreferences.getInstance();
    List<String>? value = prefs.getStringList(key) ?? [];
    return value;
  }

  static Future<bool> removeValueFromSP(String key) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.remove(key);
    return true;
  }
}
