2026-05-31 16:23:46 +02:00
|
|
|
/// All set results for one exercise in a workout session.
|
|
|
|
|
library;
|
|
|
|
|
|
|
|
|
|
import 'package:workout_app/models/exercise.dart';
|
|
|
|
|
import 'package:workout_app/models/set_result.dart';
|
|
|
|
|
|
2026-06-28 08:11:43 +02:00
|
|
|
/// Aggregated results for a single exercise across all its sets in a session.
|
2026-05-31 16:23:46 +02:00
|
|
|
class ExerciseResult {
|
2026-06-28 08:11:43 +02:00
|
|
|
/// Creates a result for [exercise] with the given [sets] outcomes.
|
2026-05-31 16:23:46 +02:00
|
|
|
const ExerciseResult({
|
|
|
|
|
required this.exercise,
|
|
|
|
|
required this.sets,
|
2026-06-06 11:39:25 +02:00
|
|
|
this.warmupDone = false,
|
2026-05-31 16:23:46 +02:00
|
|
|
});
|
|
|
|
|
|
2026-06-28 08:11:43 +02:00
|
|
|
/// The exercise definition this result belongs to.
|
2026-05-31 16:23:46 +02:00
|
|
|
final Exercise exercise;
|
2026-06-28 08:11:43 +02:00
|
|
|
|
|
|
|
|
/// Results for each individual set.
|
2026-05-31 16:23:46 +02:00
|
|
|
final List<SetResult> sets;
|
2026-06-28 08:11:43 +02:00
|
|
|
|
|
|
|
|
/// Whether the warmup set was completed before the working sets.
|
2026-06-06 11:39:25 +02:00
|
|
|
final bool warmupDone;
|
2026-05-31 16:23:46 +02:00
|
|
|
|
|
|
|
|
/// True when every set was fully completed.
|
|
|
|
|
bool get succeeded => sets.isNotEmpty && sets.every((s) => s.succeeded);
|
|
|
|
|
|
2026-06-28 08:11:43 +02:00
|
|
|
/// Serializes this exercise result to a JSON map.
|
2026-05-31 16:23:46 +02:00
|
|
|
Map<String, dynamic> toJson() => {
|
2026-06-28 08:11:43 +02:00
|
|
|
'name': exercise.name,
|
|
|
|
|
'targetSets': exercise.sets,
|
|
|
|
|
'targetReps': exercise.reps,
|
|
|
|
|
'targetWeight': exercise.weight,
|
|
|
|
|
'warmupDone': warmupDone,
|
|
|
|
|
'sets': sets.map((s) => s.toJson()).toList(),
|
|
|
|
|
'succeeded': succeeded,
|
|
|
|
|
};
|
2026-05-31 16:23:46 +02:00
|
|
|
}
|