import axios from 'axios';

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

// 新增实例
export function createInstance(params) {
  return axios.post(`${urlPrefix}/componentInstance/create`, params);
}

// 停止实例
export function stopInstance(id) {
  return axios.get(`${urlPrefix}/componentInstance/stop`, { params: { id } });
}

// 启动实例
export function startInstance(id) {
  return axios.get(`${urlPrefix}/componentInstance/start`, { params: { id } });
}

// 删除实例
export function deleteInstance(id) {
  return axios.get(`${urlPrefix}/componentInstance/remove`, { params: { id } });
}

// 刷新实例依赖
export function refreshInstanceDependency(id) {
  return axios.get(`${urlPrefix}/componentInstance/refreshDeps`, { params: { id } });
}

// 组件实例日志
export function getInstanceLog(params) {
  return axios.get(`${urlPrefix}/componentInstance/logs`, { params });
}

// 组件实例列表
export function getInstanceList(params, identifier) {
  return axios.get(`${urlPrefix}/componentInstance/list/${identifier}`, { params });
}

// 获取组件环境配置
export function getComponentEnvConfig(instanceId) {
  return axios.get(`${urlPrefix}/componentInstance/config/${instanceId}`);
}

// 保存组件环境配置
export function saveComponentEnvConfig(instanceId, params) {
  return axios.post(`${urlPrefix}/componentInstance/config/${instanceId}`, params);
}

// 本地启动
export function localStart(params) {
  return axios.get(`${urlPrefix}/componentInstance/local?componentBaseId=${params.componentBaseId}`);
}

// 组件资源
export function getComponentResource(id) {
  return axios.get(`${urlPrefix}/componentInstance/resource?id=${id}`);
}
