import { getChildrenNodeListApi, getTaskTreeApi } from '@/api/project/node';
import { translateLoadcaseTree } from '@/utils/node';
import { ElMessage } from 'element-plus';
import { getIdMap } from './project';
import { getTagMapList } from '@/utils/task';

export const getTaskTreeFun = async (projectUuid:string, phaseUuid:string) => {
  const tagMapList = getTagMapList();
  const tagSort = getIdMap(projectUuid, phaseUuid);
  console.log('tagSort', tagSort);
  const res:any = await getTaskTreeApi({
    projectNodeId: projectUuid,
    phaseNodeId: phaseUuid,
    idMap: tagSort,
    tagMap: tagMapList,
  });
  if (res.code === 200) {
    return translateLoadcaseTree(res.data);
    //  res.data;
  } else {
    ElMessage.error('获取项目任务树失败！');
    return [];
  }
};

export const getChildrenNodeList = async(nodeType:string, nodeId:string) => {
  const res:any = await getChildrenNodeListApi({ current: 1, size: 999, nodeType, nodeId });
  if (res.code === 200) {
    return res.data;
  } else {
    return [];
  }
};
