import 'package:flutter_secure_storage/flutter_secure_storage.dart';

/// Minimal secret key/value store, backed by the OS keystore in production and
/// trivially fakeable in tests. Keeps [SecureKeyStore] free of plugin calls.
abstract class SecretStore {
  Future<String?> read(String key);
  Future<void> write(String key, String value);
}

/// OS-keystore-backed implementation (Android Keystore / iOS Keychain / etc.).
class FlutterSecretStore implements SecretStore {
  FlutterSecretStore([FlutterSecureStorage? storage])
    : _storage =
          storage ??
          const FlutterSecureStorage(
            aOptions: AndroidOptions(encryptedSharedPreferences: true),
          );

  final FlutterSecureStorage _storage;

  @override
  Future<String?> read(String key) => _storage.read(key: key);

  @override
  Future<void> write(String key, String value) =>
      _storage.write(key: key, value: value);
}
