import '../security/secret_store.dart';

/// Your own display name and short "about", persisted locally (keystore-backed,
/// no plaintext at rest). The network copy is a published NIP-01 kind:0 event;
/// this local copy prefills the editor and works offline.
class ProfileStore {
  /// [accountScope] namespaces the keys per social identity (empty = the
  /// original identity's legacy keys). See [socialAccountScope].
  ProfileStore(this._store, {String accountScope = ''})
      : _base = accountScope.isEmpty
            ? 'tane.social.profile.'
            : 'tane.social.$accountScope.profile.';

  final SecretStore _store;
  final String _base;

  String get _nameKey => '${_base}name';
  String get _aboutKey => '${_base}about';
  String get _g1Key => '${_base}g1';

  Future<String> name() async => (await _store.read(_nameKey)) ?? '';
  Future<String> about() async => (await _store.read(_aboutKey)) ?? '';

  /// Your Ğ1 (Duniter) address, if you chose to share one.
  Future<String> g1() async => (await _store.read(_g1Key)) ?? '';

  Future<void> save({
    required String name,
    required String about,
    String g1 = '',
  }) async {
    await _store.write(_nameKey, name.trim());
    await _store.write(_aboutKey, about.trim());
    await _store.write(_g1Key, g1.trim());
  }
}
