import 'question.dart'; /// Status change for a question after an attempt. enum QuestionStatusChange { improved, regressed, unchanged, } /// Result of a single answer in an attempt. class AnswerResult { /// The question that was answered. final Question question; /// The indices of answers the user selected. final List userAnswerIndices; /// Deprecated: Use [userAnswerIndices] instead. Returns the first selected answer index. @Deprecated('Use userAnswerIndices instead') int get userAnswerIndex => userAnswerIndices.isNotEmpty ? userAnswerIndices.first : -1; /// Whether the answer was correct. final bool isCorrect; /// The status change for this question. final QuestionStatusChange statusChange; const AnswerResult({ required this.question, required this.userAnswerIndices, required this.isCorrect, required this.statusChange, }); } /// Result of a completed attempt. class AttemptResult { /// Total number of questions in the attempt. final int totalQuestions; /// Number of correct answers. final int correctCount; /// Percentage of correct answers. final double percentageCorrect; /// Time spent on the attempt in milliseconds. final int timeSpent; /// List of questions that were answered incorrectly. final List incorrectQuestions; /// List of all answer results. final List allResults; const AttemptResult({ required this.totalQuestions, required this.correctCount, required this.percentageCorrect, required this.timeSpent, required this.incorrectQuestions, required this.allResults, }); /// Creates an attempt result from answer results. factory AttemptResult.fromAnswers({ required List results, required int timeSpent, }) { final correctCount = results.where((r) => r.isCorrect).length; final totalQuestions = results.length; final percentageCorrect = totalQuestions > 0 ? (correctCount / totalQuestions) * 100.0 : 0.0; final incorrectQuestions = results.where((r) => !r.isCorrect).toList(); return AttemptResult( totalQuestions: totalQuestions, correctCount: correctCount, percentageCorrect: percentageCorrect, timeSpent: timeSpent, incorrectQuestions: incorrectQuestions, allResults: results, ); } }