import axios from 'axios';
import { apiResData } from '@/api/interface/index';

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

// 树形组件列表
export function getTreeComponents(params?: { name: string, identifier: string, runStatus: string }) {
  return axios.get(`${urlPrefix}/componentTestCase/tree/instance`, { params });
}

// 查询单个组件的测试用例列表
export function getComponentTestCaseList(params?: { componentBaseId: string, identifier: string }) {
  return axios.get(`${urlPrefix}/componentTestCase/tree/testcase`, { params });
}

// 提交测试用例
export function submitTestCase(params) {
  return axios.post(`${urlPrefix}/componentTestCase/submit`, params);
}

// 删除测试用例
export function deleteTestCase(ids) {
  return axios.post(`${urlPrefix}/componentTestCase/remove?ids=${ids}`);
}

// 发送测试用例
export function sendTestCase(params) {
  return axios.post(`${urlPrefix}/componentTestCase/handler`, params);
}

// 导出测试用例模板
export function exportTemplate(componentBaseId) {
  return axios.get(`${urlPrefix}/componentTestCase/export-template/${componentBaseId}`, { responseType: 'blob' });
}

// 导出当前测试用例
export function exportTestCases(componentBaseId) {
  return axios.get(`${urlPrefix}/componentTestCase/export/${componentBaseId}`, { responseType: 'blob' });
}

// 导入测试用例
export function importTestCases(params: { componentBaseId: string, file: File }) {
  const formData = new FormData();
  formData.append('file', params.file);
  return axios.post(`${urlPrefix}/componentTestCase/import/${params.componentBaseId}`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

// 开启测试用例
export function startTestCase(id) {
  return axios.get(`${urlPrefix}/componentTestCase/connect`, { params: { id } });
}

// 生成测试用例
export function generateTestCase(params: { id: string, identifier: string }) {
  return axios.post(`${urlPrefix}/componentTestCase/generationTestCase?id=${params.id}&identifier=${params.identifier}`);
}