import request from '@/utils/request';

export async function getProcessDefinitionBpmnXML(id) {
  const res = await request({
    url: '/bpm/process-definition/get-bpmn-xml?id=' + id,
    method: 'get'
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function getTaskAssignRuleList(query) {
  const res = await request({
    url: '/bpm/task-assign-rule/list',
    method: 'get',
    params: query
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function processInstanceCreateAPI(data) {
  const res = await request(
    {
      url: '/bpm/process-instance/create',
      method: 'post',
      data
    },
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function getModelPage(query) {
  const res = await request({
    url: '/bpm/model/page',
    method: 'get',
    params: query
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function getProcessDefinitionInfo(params) {
  const res = await request({
    url: `/bpm/process-definition/get`,
    method: 'get',
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function listAllUserBind() {
  const res = await request.get('/main/user/listAllUserBind');
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 获取用户组精简信息列表
export async function listSimpleUserGroups() {
  const res = await request({
    url: '/bpm/user-group/list-all-simple',
    method: 'get'
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 产品分类指定code查询
 */

export async function getProduceTreeByCode(code) {
  const res = await request.get(
    `/main/categoryLevel/getProduceTreeByPid?code=${code}`,
    {}
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}