import 'package:mmkv/mmkv.dart';

class KVUtil {
  KVUtil._();

  static MMKV? mmkv;

  static init() async {
    await MMKV.initialize();
    mmkv = MMKV.defaultMMKV();
  }

  static void putString(String key, String? value) {
    mmkv?.encodeString(key, value);
  }

  static String? getString(String key, String? defaultValue) {
    return mmkv?.decodeString(key) ?? defaultValue;
  }

  static void putInt(String key, int value) {
    mmkv?.encodeInt(key, value);
  }

  static int? getInt(String key, int defaultValue) {
    return mmkv?.decodeInt(key, defaultValue: defaultValue);
  }

  static void putBool(String key, bool value) {
    mmkv?.encodeBool(key, value);
  }

  static bool? getBool(String key, bool defaultValue) {
    return mmkv?.decodeBool(key, defaultValue: defaultValue);
  }

  static void putDouble(String key, double value) {
    mmkv?.encodeDouble(key, value);
  }

  static double? getDouble(String key, double defaultValue) {
    return mmkv?.decodeDouble(key, defaultValue: defaultValue);
  }
}
