import 'package:shared_preferences/shared_preferences.dart'; class QuizPrefs { static const String _kSeenQuizKey = 'seen_oral_quiz_v1'; static const String _kLastScoreKey = 'last_oral_quiz_score_v1'; static const String _kLastMaxScoreKey = 'last_oral_quiz_max_score_v1'; static String _scopeKey(String base, String? scopeId) { final id = (scopeId ?? '').trim(); if (id.isEmpty) return base; return '${base}_$id'; } static Future hasSeenQuiz() async { final prefs = await SharedPreferences.getInstance(); return prefs.getBool(_kSeenQuizKey) ?? false; } static Future markQuizSeen() async { final prefs = await SharedPreferences.getInstance(); await prefs.setBool(_kSeenQuizKey, true); } static Future saveLastResult({required int score, required int maxScore}) async { final prefs = await SharedPreferences.getInstance(); await prefs.setInt(_kLastScoreKey, score); await prefs.setInt(_kLastMaxScoreKey, maxScore); } static Future saveLastResultForUser({required String userId, required int score, required int maxScore}) async { await saveLastResultForScope(scopeId: userId, score: score, maxScore: maxScore); } static Future saveLastResultForScope({required String scopeId, required int score, required int maxScore}) async { final prefs = await SharedPreferences.getInstance(); await prefs.setInt(_scopeKey(_kLastScoreKey, scopeId), score); await prefs.setInt(_scopeKey(_kLastMaxScoreKey, scopeId), maxScore); } static Future getLastScore() async { final prefs = await SharedPreferences.getInstance(); return prefs.getInt(_kLastScoreKey); } static Future getLastScoreForUser(String userId) async { return getLastScoreForScope(userId); } static Future getLastScoreForScope(String scopeId) async { final prefs = await SharedPreferences.getInstance(); return prefs.getInt(_scopeKey(_kLastScoreKey, scopeId)); } static Future getLastMaxScore() async { final prefs = await SharedPreferences.getInstance(); return prefs.getInt(_kLastMaxScoreKey); } static Future getLastMaxScoreForUser(String userId) async { return getLastMaxScoreForScope(userId); } static Future getLastMaxScoreForScope(String scopeId) async { final prefs = await SharedPreferences.getInstance(); return prefs.getInt(_scopeKey(_kLastMaxScoreKey, scopeId)); } }