import 'package:food_delivery_client/food_delivery_client.dart';

@singleton
class StorageService {
  static late SharedPreferences _sharedPreference;

  Future<void> initialize() async {
    _sharedPreference = await SharedPreferences.getInstance();
  }

  void setString({required String key, required String value}) {
    _sharedPreference.setString(key, value);
  }

  void setStringList({required String key, required String value}) {
    final oldList = _sharedPreference.getStringList(key);
    final newList = oldList?..add(value);
    _sharedPreference.setStringList(key, newList ?? []);
  }

  List<String> getStringList({required String key}) {
    return _sharedPreference.getStringList(key) ?? [];
  }

  String? getString({required String key}) {
    return _sharedPreference.getString(key);
  }
}

/*
static StorageService? _instance;

  const StorageService._();

  static Future<StorageService> initialize() async {
    if (_instance == null) {
      _sharedPreference = await SharedPreferences.getInstance();
      _instance = StorageService._();
    }
    return _instance!;
  }
 */
