import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'providers.dart';

/// Reactive view over SaveRepository's endless best score.
class EndlessBestNotifier extends Notifier<int> {
  @override
  int build() => ref.read(saveRepositoryProvider).endlessBest;

  /// Records the run; returns true when it set a new best.
  Future<bool> record(int score) async {
    final repo = ref.read(saveRepositoryProvider);
    final isNewBest = score > state;
    await repo.recordEndlessScore(score);
    state = repo.endlessBest;
    return isNewBest;
  }
}
