import 'package:shared_preferences/shared_preferences.dart';

class AuthStorage {
  static const _keyToken = 'auth_token';
  static const _keyDriverOnline = 'driver_online';

  static Future<void> setToken(String token) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setString(_keyToken, token);
  }

  static Future<String?> getToken() async {
    final prefs = await SharedPreferences.getInstance();
    return prefs.getString(_keyToken);
  }

  static Future<void> clearToken() async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.remove(_keyToken);
  }

  /// Last known driver online state (for toggle persistence across app restarts).
  static Future<bool?> getDriverOnline() async {
    final prefs = await SharedPreferences.getInstance();
    return prefs.getBool(_keyDriverOnline);
  }

  static Future<void> setDriverOnline(bool online) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setBool(_keyDriverOnline, online);
  }
}
