import 'package:audioplayers/audioplayers.dart';

abstract interface class ExerciseStepAudioCuePlayer {
  Future<void> playShortCountdownBeep();

  Future<void> playLongCompletionBeep();

  Future<void> dispose();
}

final class AudioplayersExerciseStepAudioCuePlayer
    implements ExerciseStepAudioCuePlayer {
  AudioplayersExerciseStepAudioCuePlayer();

  final AudioPlayer _player = AudioPlayer();

  @override
  Future<void> playShortCountdownBeep() {
    return _play('audio/step_countdown_short.wav');
  }

  @override
  Future<void> playLongCompletionBeep() {
    return _play('audio/step_completion_long.wav');
  }

  Future<void> _play(String assetPath) async {
    await _player.stop();
    await _player.play(AssetSource(assetPath));
  }

  @override
  Future<void> dispose() {
    return _player.dispose();
  }
}

final class NoOpExerciseStepAudioCuePlayer
    implements ExerciseStepAudioCuePlayer {
  const NoOpExerciseStepAudioCuePlayer();

  @override
  Future<void> playShortCountdownBeep() async {}

  @override
  Future<void> playLongCompletionBeep() async {}

  @override
  Future<void> dispose() async {}
}
