import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../data/save_repository.dart';
import 'providers.dart';

/// Exposes saved progress as immutable state so screens rebuild when stars
/// land; persistence goes through [SaveRepository].
class ProgressNotifier extends Notifier<Map<String, StageProgress>> {
  @override
  Map<String, StageProgress> build() =>
      ref.read(saveRepositoryProvider).snapshot();

  Future<void> record({
    required String seasonId,
    required String stageId,
    required int stars,
    required int score,
  }) async {
    final repo = ref.read(saveRepositoryProvider);
    await repo.recordResult(
      seasonId: seasonId,
      stageId: stageId,
      stars: stars,
      score: score,
    );
    state = repo.snapshot();
  }
}
