import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';

class StorageService extends GetxService {
  static StorageService get to => Get.find();
  late final GetStorage _getStorage;
  get storage => _getStorage;

  Future<StorageService> init() async {
    await GetStorage.init();
    _getStorage = GetStorage();
    return this;
  }

  T? read<T>(String key) {
    return _getStorage.read<T>(key);
  }

  Future<void> write(String key, dynamic value) async {
    return await _getStorage.write(key, value);
  }

  Future<void> remove(String key) async {
    return await _getStorage.remove(key);
  }

  bool hasData(String key) {
    return _getStorage.hasData(key);
  }

  Future erase() async {
    await _getStorage.erase();
  }
}
