// ===========================================================================
// FILE: lib/services/audio_service.dart
// ===========================================================================

import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
import '../core/app_colors.dart';

class AudioService extends ChangeNotifier {
  static final AudioService instance = AudioService._internal();
  AudioService._internal();

  bool isMuted = false;
  final AudioPlayer _sfxPlayer = AudioPlayer();

  void toggleMute() {
    isMuted = !isMuted;
    notifyListeners();
  }

  void playLineSfx(AppThemeType theme) async {
    if (isMuted) return;
    String file = '';
    switch (theme) {
      case AppThemeType.minimal:
      case AppThemeType.arcade: // Suono secco per l'arcade
        file = 'minimal_line.wav'; break;
      case AppThemeType.doodle:
      case AppThemeType.wood:
        file = 'doodle_line.wav'; break;
      case AppThemeType.cyberpunk:
      case AppThemeType.grimorio: // Suono etereo per la magia
        file = 'cyber_line.wav'; break;
    }
    await _sfxPlayer.play(AssetSource('audio/sfx/$file'));
  }

  void playBoxSfx(AppThemeType theme) async {
    if (isMuted) return;
    String file = '';
    switch (theme) {
      case AppThemeType.minimal:
      case AppThemeType.arcade:
        file = 'minimal_box.wav'; break;
      case AppThemeType.doodle:
      case AppThemeType.wood:
        file = 'doodle_box.wav'; break;
      case AppThemeType.cyberpunk:
      case AppThemeType.grimorio:
        file = 'cyber_box.wav'; break;
    }
    await _sfxPlayer.play(AssetSource('audio/sfx/$file'));
  }

  void playBonusSfx() async {
    if (isMuted) return;
    await _sfxPlayer.play(AssetSource('audio/sfx/bonus.wav'));
  }

  void playBombSfx() async {
    if (isMuted) return;
    await _sfxPlayer.play(AssetSource('audio/sfx/bomb.wav'));
  }
}