import axios from 'axios';
import { FlowDefinition, appFlowModel, queryParams } from '@/api/interface/index';

// 公共路径
const urlPrefix = '/api/v1/bpms-workbench';

// 获取应用资源
export function getAppInfo(data: string) {
  return axios.get(`${urlPrefix}/appRes/${data}`);
}

// 更新主流程
export function setMainFlow(data: FlowDefinition, appId: string) {
  return axios.post(`${urlPrefix}/appRes/${appId}/updateMain`, data);
}

// 新增子流程
export function addSub(appId: string, data?: FlowDefinition[]) {
  return axios.post(
    `${urlPrefix}/appRes/${appId}/addSub`,
    data || {
      lineConfigs: [],
      nodeConfigs: []
    }
  );
}

// 删除子流程
export function deleteSub(id: string, appId: string) {
  return axios.delete(`${urlPrefix}/appRes/${appId}/sub/${id}`);
}

// 更新子流程
export function setSubFlow(data: FlowDefinition, appId: string) {
  return axios.post(`${urlPrefix}/appRes/${appId}/updateSub`, data);
}

// 导入子流程
export function addSubComp(data: appFlowModel, appId: string) {
  return axios.post(`${urlPrefix}/appRes/${appId}/addSubComp`, data);
}

// 导入组件
export function importComponenets(data: appFlowModel, appId: string) {
  return axios.post(`${urlPrefix}/appRes/${appId}/addComp`, data);
}

// 根据主流程id分页
export function historyPage(data: queryParams) {
  return axios.post(`${urlPrefix}/appRes/historyPage`, data);
}

// 获取历史应用资源
export function getHistoryDetail(appId: string, historyId: string) {
  return axios.get(`${urlPrefix}/appRes/${appId}/historyDetail/${historyId}`);
}

// 添加已发布流程到子流程
export function addPublishSub(data: FlowDefinition, appId: string) {
  return axios.post(`${urlPrefix}/appRes/${appId}/addPublishSub`, data);
}
