import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { MainVO, MainForm, MainQuery, ParmsValueVo } from '@/api/rule/definition/mian_types';
import { InputParameterVO } from '@/api/rule/definition/parms_types';
import { Cell } from '@antv/x6';


/**
 * 查询规则信息主列表
 * @param query
 * @returns {*}
 */

export const listMain = (query?: MainQuery): AxiosPromise<MainVO[]> => {
  return request({
    url: '/rule/main/list',
    method: 'get',
    params: query
  });
};
/**
 * 查询规则信息主详细
 * @param rulesId
 */
export const getMain = (rulesId: string | number): AxiosPromise<MainVO> => {
  return request({
    url: '/rule/main/' + rulesId,
    method: 'get'
  });
};

/**
 * 新增规则信息主
 * @param data
 */
export const addMain = (data: MainForm) => {
  return request({
    url: '/rule/main',
    method: 'post',
    data: data
  });
};

/**
 * 修改规则信息主
 * @param data
 */
export const updateMain = (data: MainForm) => {
  return request({
    url: '/rule/main',
    method: 'put',
    data: data
  });
};

export const save = (rulesId: string | number, TreeData: { cells: Cell.Properties[] }) => {
  const data = {
    rulesId,
    TreeData
  };
  return request({
    url: '/rule/main/saveDecisionTree',
    method: 'post',
    data: data
  });
};

export const getRulseMap = (rulesId: string | number) => {
  const data = {
    rulesId
  };
  return request({
    url: '/rule/main/queryDecisionTree',
    method: 'post',
    data: data
  });
};

export const getParms = (rulesId: string | number): AxiosPromise<InputParameterVO> => {
  const data = {
    rulesId
  };
  return request({
    url: '/rule/parameter/getParmsList',
    method: 'post',
    data: data
  });
};

export const addParms = (rulesId: string | number, parms: Array<InputParameterVO>) => {
  const data = {
    rulesId,
    parms
  };
  return request({
    url: '/rule/parameter/addParameter',
    method: 'post',
    data: data
  });
};

export const quryRulesParms = (rulesId: string | number) => {
  const data = {
    rulesId
  };
  return request({
    url: '/rule/parameter/quryRulesParms',
    method: 'post',
    data: data
  });
};

export const saveRulesDecisionTreeDetail = (rulesId: string | number, nodeType: string, nodeId: string, nodeDetail: JSON) => {
  const data = {
    rulesId,
    nodeType,
    nodeId,
    nodeDetail
  };
  return request({
    url: '/rule/parameter/saveRulesDecisionTreeDetail',
    method: 'post',
    data: data
  });
};

export const getConditionRulesDecisionTreeDetail = (rulesId: string | number, nodeId: string, nextNodeId: string) => {
  const data = {
    rulesId,
    nodeId,
    nextNodeId
  };
  return request({
    url: '/rule/parameter/getConditionRulesDecisionTreeDetail',
    method: 'post',
    data: data
  });
};

export const getFiltersRulesDecisionTreeDetail = (rulesId: string | number, nodeId: string) => {
  const data = {
    rulesId,
    nodeId
  };
  return request({
    url: '/rule/parameter/getFiltersRulesDecisionTreeDetail',
    method: 'post',
    data: data
  });
};

export const getEditsRulesDecisionTreeDetail = (rulesId: string | number, nodeId: string) => {
  const data = {
    rulesId,
    nodeId
  };
  return request({
    url: '/rule/parameter/getEditsRulesDecisionTreeDetail',
    method: 'post',
    data: data
  });
};
export const quryDecimalParms = (rulesId: string | number) => {
  const data = {
    rulesId
  };
  return request({
    url: '/rule/parameter/quryDecimalParms',
    method: 'post',
    data: data
  });
};

export const saveCalendarParms = (rulesId: string | number, nodeType: string, nodeId: string, calendarMula: string, nodeDetail: JSON) => {
  const data = {
    rulesId,
    nodeType,
    nodeId,
    calendarMula,
    nodeDetail
  };
  return request({
    url: '/rule/parameter/saveRulesDecisionTreeDetail',
    method: 'post',
    data: data
  });
};

export const getCalendarRulesDecisionTreeDetail = (rulesId: string | number, nodeId: string) => {
  const data = {
    rulesId,
    nodeId
  };
  return request({
    url: '/rule/parameter/getCalendarRulesDecisionTreeDetail',
    method: 'post',
    data: data
  });
};

export const parsingRules = (rulesId: string | number) => {
  const data = {
    rulesId
  };
  return request({
    url: '/rule/main/parsingRules',
    method: 'post',
    data: data
  });
};

export const checkParsing = (rulesId: string | number) => {
  const data = {
    rulesId
  };
  return request({
    url: '/rule/main/checkParsing',
    method: 'post',
    data: data
  });
};

export const executionRule = (rulesId: string | number, parmsValue: Array<ParmsValueVo>) => {
  const data = {
    rulesId,
    parmsValue
  };
  return request({
    url: '/rule/main/executionRule',
    method: 'post',
    data: data
  });
};

export const deleteRule = (data: MainForm) => {
  return request({
    url: '/rule/main/deleteTree',
    method: 'post',
    data: data
  });
};

export const ruleToAudit = (data: MainForm) => {
  return request({
    url: '/rule/main/ruleToAudit',
    method: 'post',
    data: data
  });
};

export const ruleAudit = (auditResult: boolean, rulesId: string | number, message: string) => {
  const data = {
    auditResult,
    rulesId,
    message
  };
  return request({
    url: '/rule/main/ruleAudit',
    method: 'post',
    data: data
  });
};

export const releaseStateChange = (data: MainForm) => {
  return request({
    url: '/rule/main/releaseStateChange',
    method: 'post',
    data: data
  });
};
