import '../models/bo/linkage_rule_bo.dart';
import '../repositories/linkage_rule_repository.dart';

class LinkageRuleService {
  final LinkageRuleRepository _repository;

  LinkageRuleService({required LinkageRuleRepository repository})
      : _repository = repository;

  /// 获取联动规则列表
  Future<List<LinkageRuleBO>> getRules() async {
    final result = await _repository.getRules();
    if (result.success && result.data != null) {
      return result.data!;
    }
    throw Exception(result.msg);
  }

  /// 启用/禁用联动规则
  Future<LinkageRuleToggleBO> toggleRule({
    required int ruleId,
    required String enabled,
  }) async {
    final result = await _repository.toggleRule(
      ruleId: ruleId,
      enabled: enabled,
    );
    if (result.success && result.data != null) {
      return result.data!;
    }
    throw Exception(result.msg);
  }
}
