abstract class JwtTokenStorage {
  /// Save both access and refresh tokens
  ///
  /// @param accessToken The short-lived access token
  /// @param refreshToken The long-lived refresh token
  Future<void> saveTokens(String accessToken, String refreshToken);

  /// Get the stored access token
  ///
  /// @return Access token or null if not found
  Future<String?> getAccessToken();

  /// Get the stored refresh token
  ///
  /// @return Refresh token or null if not found
  Future<String?> getRefreshToken();

  /// Clear all stored tokens (on logout)
  Future<void> clearTokens();

  /// Check if tokens are stored
  ///
  /// @return true if access token exists
  Future<bool> hasTokens();

  /// Update only the access token (used after refresh)
  ///
  /// @param accessToken New access token
  Future<void> updateAccessToken(String accessToken);
}

class JwtTokenStorageImpl extends JwtTokenStorage {
  
  // Storage keys
  String? _keyAccessToken;
  String? _keyRefreshToken;

  @override
  Future<void> saveTokens(String accessToken, String refreshToken) async {
    _keyAccessToken = accessToken;
    _keyRefreshToken = refreshToken;
  }

  @override
  Future<String?> getAccessToken() async {
    return _keyAccessToken;
  }

  @override
  Future<String?> getRefreshToken() async {
    return _keyRefreshToken;
  }

  @override
  Future<void> clearTokens() async {
    _keyAccessToken = null;
    _keyRefreshToken = null;
  }

  @override
  Future<bool> hasTokens() async {
    return _keyAccessToken != null && _keyAccessToken!.isNotEmpty;
  }

  @override
  Future<void> updateAccessToken(String accessToken) async {
    _keyAccessToken == accessToken;
  }
}
