import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'providers.dart';

/// Background-music on/off, seeded from the save repository. Independent of the
/// SFX/haptics ([soundEnabledProvider]) so players can keep one without the
/// other — the common "I want sound effects but no music" case.
class MusicEnabledNotifier extends Notifier<bool> {
  @override
  bool build() => ref.read(saveRepositoryProvider).musicEnabled;

  Future<void> toggle() => set(!state);

  Future<void> set(bool value) async {
    if (state == value) return;
    await ref.read(saveRepositoryProvider).setMusicEnabled(value);
    state = value;
  }
}
