import 'package:flutter_secure_storage/flutter_secure_storage.dart';

/// ذخیره‌ی امن توکن JWT و شماره‌ی موبایلِ کاربر.
class TokenStorage {
  static const _key = 'jwt_token';
  static const _mobileKey = 'user_mobile';
  final FlutterSecureStorage _storage;

  TokenStorage([FlutterSecureStorage? storage])
      : _storage = storage ?? const FlutterSecureStorage();

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

  Future<void> write(String token) => _storage.write(key: _key, value: token);

  Future<String?> readMobile() => _storage.read(key: _mobileKey);

  Future<void> writeMobile(String mobile) =>
      _storage.write(key: _mobileKey, value: mobile);

  Future<void> clear() async {
    await _storage.delete(key: _key);
    await _storage.delete(key: _mobileKey);
  }
}
