// Version: 2.0.0 | Created: 2026-04-01 | Updated: 2026-04-11
// Minimal storage: only the Matrix device ID is persisted so that
// encryption keys accumulate on one device across logins.
// Access tokens are NOT stored — every browser visit requires login.

import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'secure_storage.g.dart';

@Riverpod(keepAlive: true)
SecureStorage secureStorage(Ref ref) => const SecureStorage();

class SecureStorage {
  const SecureStorage();

  static const _kDeviceId = 'm8chat_device_id';

  static const FlutterSecureStorage _storage = FlutterSecureStorage(
    aOptions: AndroidOptions(encryptedSharedPreferences: true),
  );

  Future<void> saveDeviceId(String deviceId) async {
    await _storage.write(key: _kDeviceId, value: deviceId);
  }

  Future<String?> loadDeviceId() async {
    return _storage.read(key: _kDeviceId);
  }
}
