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

class AuthService {
  static const _tokenKey = 'auth_token';
  static const _storage = FlutterSecureStorage();

  // Save token after login
  static Future<void> saveToken(String token) async {
    print("SAveTOken");
    await _storage.write(key: _tokenKey, value: token);
  }

  // Read token
  static Future<String?> getToken() async {
    return await _storage.read(key: _tokenKey);
  }

  // Delete token (logout)
  static Future<void> clearToken() async {
    print('ClearToken');
    final prefs = await SharedPreferences.getInstance();
    prefs.clear();
    await _storage.delete(key: _tokenKey);
  }

  // Check if logged in
  static Future<bool> isLoggedIn() async {
    final token = await getToken();
    return token != null && token.isNotEmpty;
  }
}

// if (success) {
// await AuthService.saveToken("my-secure-jwt-token");
// if (mounted) context.go(AppRoutes.home);
// }
