import { config, networkUtils } from '../../utils';

const { request } = networkUtils;
const { api } = config;
const { bpm } = api;
const { examine, trace, diagram, assignees, checkActived, bpmInfo, formCfg } = bpm;

export async function getTrace(prcId) {
  return request({
    url: trace.replace('{prcId}', prcId),
    method: 'get',
  });
}

export async function getDiagram(def) {
  return request({
    url: diagram,
    method: 'get',
    data: { id: def },
  });
}

export async function getAssignees(prcId) {
  return request({
    url: assignees.replace('{prcId}', prcId),
    method: 'get',
  });
}

export async function doApprove(params) {
  const { taskId, advice } = params;
  return request({
    url: examine,
    method: 'post',
    data: { result: 'APPROVED', taskId, advice },
  });
}

export async function doReject(params) {
  const { taskId, advice } = params;
  return request({
    url: examine,
    method: 'post',
    data: { result: 'REJECTED', taskId, advice },
  });
}

export async function doContinued(params) {
  const { taskId, advice } = params;
  return request({
    url: examine,
    method: 'post',
    data: { result: 'CONTINUED', taskId, advice },
  });
}

export async function doBatchApprove(params) {
  // const { taskIds, advice } = params;
  return request({
    url: examine,
    method: 'post',
    data: { result: 'APPROVED', ...params },
  });
}

export async function doBatchReject(params) {
  // const { taskIds, advice } = params;
  return request({
    url: examine,
    method: 'post',
    data: { result: 'REJECTED', ...params },
  });
}

export async function doDisabled(params) {
  const { taskId, advice } = params;
  return request({
    url: examine,
    method: 'post',
    data: { result: 'DISABLED', taskId, advice },
  });
}

/**
 * 检查当前用户是否活动任务的处理人
 * @param   {String} prcId
 * @return  {Boolean} true/false
 */
export async function doCheckActived(prcId) {
  return request({
    url: checkActived.replace('{prcId}', prcId),
    method: 'get',
  });
}

export async function getBpmInfo(defId) {
  return request({
    url: bpmInfo,
    method: 'get',
    data: { defId },
  });
}

/**
 * 获取表单配置
 * @param   {params} Object
 *  defId: 'ATypeContract:',
 *  nodeId: 'initiator',
 *  mode: 'edit',
 * @return  {Object} 配置信息
 */

export async function getFormCfg(params) {
  return request({
    url: formCfg,
    method: 'get',
    data: params,
  });
}
