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';
import { getSeeDisciplines } from '@/tenants/lyric/views/task/lyricTask';

export const getTaskTreeFun = async (
  projectUuid: string,
  phaseUuid: string,
  queryTaskFlag: number = 0
) => {
  const tagMapList = getTagMapList();
  const tagSort = getIdMap(projectUuid, phaseUuid);
  const filterDiscipline = getSeeDisciplines();
  const res: any = await getTaskTreeApi({
    projectNodeId: projectUuid,
    phaseNodeId: phaseUuid,
    idMap: tagSort,
    tagMap: tagMapList,
    filterDiscipline,
    queryTaskFlag: queryTaskFlag, // 1 过滤掉任务和指标 ，其他数字不过滤
  });
  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 [];
  }
};
