import '../utils/http/response_model.dart';
import '../utils/http/dio_request.dart';
import '../models/bo/linkage_rule_bo.dart';

class LinkageRuleRepository {
  /// 获取联动规则列表
  /// GET /app/linkage/rules
  Future<ResponseModel<List<LinkageRuleBO>>> getRules() {
    return DioRequest.instance.get<List<LinkageRuleBO>>(
      '/app/linkage/rules',
      fromJsonT: (data) {
        final list = data as List<dynamic>;
        return list
            .map((e) => LinkageRuleBO.fromJson(e as Map<String, dynamic>))
            .toList();
      },
    );
  }

  /// 启用/禁用联动规则
  /// PUT /app/linkage/rules/toggle
  Future<ResponseModel<LinkageRuleToggleBO>> toggleRule({
    required int ruleId,
    required String enabled,
  }) {
    return DioRequest.instance.put<LinkageRuleToggleBO>(
      '/app/linkage/rules/toggle',
      data: {'ruleId': ruleId, 'enabled': enabled},
      fromJsonT: (data) =>
          LinkageRuleToggleBO.fromJson(data as Map<String, dynamic>),
    );
  }
}
