import 'package:flutter/material.dart';
import 'package:hub/shared/helpers/base_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';

class SharedPreferencesStorage implements BaseStorage {
  SharedPreferencesStorage._();

  static final SharedPreferencesStorage instance = SharedPreferencesStorage._();

  late final SharedPreferences _prefs;

  @override
  Future<void> init() async {
    _prefs = await SharedPreferences.getInstance();
  }

  @override
  Future<String?> get(String key) async {
    return _prefs.get(key).toString();
  }

  @override
  Future<void> set(String key, String value) async {
    await _prefs.setString(key, value);
  }

  @override
  Future<void> delete(String key) async {
    await _prefs.remove(key);
  }

  @override
  Future<void> clearAll() async {
    await _prefs.clear();
  }
}
