import 'package:get/get.dart';
import 'package:flashlink/app/data/sp/ix_sp.dart';
import 'package:flashlink/app/constants/sp_keys.dart';

enum RoutingMode { smart, global }

class RoutingmodeController extends GetxController {
  // 当前选中的路由模式，默认为Smart
  final selectedMode = RoutingMode.smart.obs;

  @override
  void onInit() {
    super.onInit();
    _loadSelectedMode();
  }

  /// 加载保存的模式
  void _loadSelectedMode() {
    final modeString = IXSP.getString(SPKeys.routingModeSelected);
    if (modeString != null) {
      selectedMode.value = modeString == 'global'
          ? RoutingMode.global
          : RoutingMode.smart;
    }
  }

  /// 保存选中的模式
  void _saveSelectedMode() {
    final modeString = selectedMode.value == RoutingMode.global
        ? 'global'
        : 'smart';
    IXSP.setString(SPKeys.routingModeSelected, modeString);
  }

  /// 选择路由模式
  void selectMode(RoutingMode mode) {
    selectedMode.value = mode;
    _saveSelectedMode();
  }
}
