import '../../../shared/utils/app_logger.dart';

const _tag = 'SeekGuard';


class SeekGuard {
  SeekGuard({this.tolerance = const Duration(seconds: 2)});

  final Duration tolerance;

  Duration? _target;

  void arm(Duration target) {
    _target = target > Duration.zero ? target : null;
  }

  void disarm() {
    _target = null;
  }

  bool shouldSuppress(Duration reported) {
    final guard = _target;
    if (guard == null) return false;

    if (reported < guard - tolerance) {
      AppLogger.debug(
        _tag,
        'Suppressing reported position $reported below target $guard',
      );
      return true;
    }

    disarm();
    return false;
  }
}
