import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'shared/settings_persistence.dart';


enum PlayerEngineOverride {
  auto('自动'),
  fvp('fvp (libmdk)'),
  mpv('mpv (media_kit)'),
  media3('Media3 (ExoPlayer+FFmpeg)');

  final String label;
  const PlayerEngineOverride(this.label);
}

class PlayerEngineOverrideNotifier extends AsyncNotifier<PlayerEngineOverride>
    with SettingsPersistence {
  static const _key = 'smplayer.player_engine_override';

  @override
  Future<PlayerEngineOverride> build() async {
    final prefs = await getPrefs();
    final raw = prefs.getString(_key);
    if (raw == null) return PlayerEngineOverride.auto;
    try {
      return PlayerEngineOverride.values.byName(raw);
    } catch (_) {
      return PlayerEngineOverride.auto;
    }
  }

  Future<void> setOverride(PlayerEngineOverride value) async {
    state = AsyncValue.data(value);
    await persistField(_key, value.name);
  }
}

final playerEngineOverrideProvider =
    AsyncNotifierProvider<PlayerEngineOverrideNotifier, PlayerEngineOverride>(
      PlayerEngineOverrideNotifier.new,
    );
