/// Cumulative guess / prospective-question score from the API. class GuessScoreSummary { const GuessScoreSummary({ required this.total, required this.answersTotal, required this.answersCorrect, required this.percentCorrect, this.slotStart, this.newerSlotStart, }); final num total; final int answersTotal; final int answersCorrect; final num percentCorrect; /// Older edge of the active session-half pair in the history window. final DateTime? slotStart; /// Newer edge of the active pair (next session half after [slotStart]). final DateTime? newerSlotStart; static const GuessScoreSummary empty = GuessScoreSummary( total: 0, answersTotal: 0, answersCorrect: 0, percentCorrect: 0, ); factory GuessScoreSummary.fromJson(Map json) { final int answersTotal = (json['answersTotal'] as num?)?.toInt() ?? 0; final int answersCorrect = (json['answersCorrect'] as num?)?.toInt() ?? 0; final num? percentRaw = json['percentCorrect'] as num?; final num percentCorrect = percentRaw ?? (answersTotal > 0 ? (answersCorrect / answersTotal) * 100 : 0); return GuessScoreSummary( total: json['total'] as num? ?? 0, answersTotal: answersTotal, answersCorrect: answersCorrect, percentCorrect: percentCorrect, slotStart: _parseOptionalUtc(json['slotStart'] as String?), newerSlotStart: _parseOptionalUtc(json['newerSlotStart'] as String?), ); } static DateTime? _parseOptionalUtc(String? wire) { if (wire == null || wire.isEmpty) { return null; } return DateTime.tryParse(wire)?.toUtc(); } }