import 'package:hub/features/local/index.dart';
import 'package:hub/features/profile/index.dart';
import 'package:hub/features/storage/index.dart';

class DatabaseStorage implements BaseStorage {
  DatabaseStorage._();

  static final DatabaseStorage instance = DatabaseStorage._();

  // static final DatabaseStorage instance = DatabaseStorage._();

  // late final Database _database;
  // bool _isInitialized = false;

  static BaseStorage getInstanceByKey(String key) {
    if (ProfileStorageKey.keys.contains(key)) //
    {
      return ProfileLocalDataSourceImpl();
    } else //if (LocalsStorageKey.values.contains(key))
    {
      return LocalsLocalDataSourceImpl();
    }
  }

  @override
  Future<void> clearAll() async {
    await ProfileLocalDataSourceImpl().clearAll();
    await LocalsLocalDataSourceImpl().clearAll();
  }

  @override
  Future<void> delete(String key) async =>
      await getInstanceByKey(key).delete(key);

  @override
  Future<String?> get(String key) async => //
      await getInstanceByKey(key).get(key);

  @override
  Future<void> init() async => //
      await DatabaseService.instance.init();

  @override
  Future<void> set<T>(String key, T value) async =>
      await getInstanceByKey(key).set(key, value);
}
