import request from './request.js'

/**
 *
 * 查询当前用户的指定级别领导
 * @param level 指定级别
 * @param deptId 部门ID
 * @param skipEmpty 是否跳过空部门
 * @returns {Promise<unknown>}
 */
export function getUserLeader(level, deptId, skipEmpty){
  return request({
    url: `wflow/process/step/leader/level`,
    method: 'get',
    data: {level: level, deptId: deptId, skipEmpty: skipEmpty}
  }, false)
}

/**
 * 查询当前用户的指定级别下的所有领导
 * @param maxLevel 截至级别，为空则直到顶级
 * @param deptId 部门ID
 * @param skipEmpty 是否跳过空部门
 */
export function getUserLeaders(maxLevel, deptId, skipEmpty){
  return request({
    url: `wflow/process/step/leader/to/level`,
    method: 'get',
    data: {maxLevel: maxLevel, deptId: deptId, skipEmpty: skipEmpty}
  }, false)
}

/**
 * 获取指定系统角色的所有人员
 * @param roles
 */
export function getUsersByRoles(roles){
  return request({
    url: `wflow/process/step/userByRoles`,
    method: 'post',
    data: roles
  }, false)
}

/**
 * 查询所有部门主管
 * @param deptIds 部门ID
 */
export function getLeaderByDepts(deptIds){
  return request({
    url: `wflow/process/step/deptLeader`,
    method: 'post',
    data: deptIds
  }, false)
}

export function getNewVerProcess(code, isSub = false){
  return request({
    url: `wflow/process/model${isSub ? '/sub':''}/${code}`,
    method: 'get'
  })
}

export function saveProcess(params, isSub = false){
  return request({
    url: `wflow/process/model${isSub ? '/sub': ''}/save/`,
    method: 'post',
    data: params
  })
}

export function deployProcess(code, isSub = false){
  return request({
    url: `wflow/process/model${isSub ? '/sub': ''}/deploy/${code}`,
    method: 'post'
  })
}

export function getCustomPrintConfig(instanceId){
  return request({
    url: `wflow/process/model/customPrint/${instanceId}`,
    method: 'get'
  })
}

export function delProcessInst(instanceId){
  return request({
    url: `wflow/process/instance/${instanceId}`,
    method: 'delete'
  })
}

export function startProcess(code, params){
  return request({
    url: `wflow/process/start/${code}`,
    method: 'post',
    data: params
  })
}

//查询条件节点的所有满足的条件分支
export function getTrueConditions(params){
  return request({
    url: `/wflow/process/step/conditions/resolve`,
    method: 'post',
    data: params
  }, false)
}

//校验EL表达式
export function validateEl(el){
  return request({
    url: `/wflow/process/step/el/validate`,
    method: 'get',
    data: {el: el}
  })
}

export default {
  getUserLeader, getUserLeaders, getUsersByRoles, validateEl,
  deployProcess, saveProcess, getNewVerProcess, getCustomPrintConfig,
  getLeaderByDepts, delProcessInst, getTrueConditions
}
