import request from '@/utils/request';
import { MockData } from '@/mock/leftTree.js';
import { MockData_r } from '@/mock/rightTree.js';
import { data } from '@/mock/funcFailNet.js';
import { fengXian } from '@/mock/fengXianFenXi.js';

// 获取风险分析数据
export function getRiskData(params) {
  return new Promise(function (resolve, reject) {
    resolve(fengXian);
  });
}

// 获取左侧的结构树
export function getStruTree(params) {
  return new Promise(function (resolve, reject) {
    resolve(MockData);
  });
  return request({
    url: request.apiModule.rdfm + '/structure/tree/left',
    method: 'get',
    params
  })
}

//fmeaExport fmea导出
export function postFmeaExport(data) {
  return request({
    url: request.apiModule.rdfm + '/structure/export',
    method: 'post',
    data
  })
}

//excel导入
export function importExcel(data) {
  return request({
    url: request.apiModule.rdfm + '/structure/import-excel',
    method: 'upload',
    data
  })
}

//fmeaImport fmea导入
export function putFmeaImport(data) {
  return request({
    url: request.apiModule.rdfm + '/structure/import',
    method: 'put',
    data
  })
}

//历史输入查询，历史添加，获取结构
export function getHistory(params) {
  return request({
    url: request.apiModule.rdfm + '/structure/history/',
    method: 'get',
    params
  })
}

//节点转换
export function getStruSwitch(id) {
  return request({
    url: request.apiModule.rdfm + '/structure/type/',
    method: 'put',
    data: { id: id }
  })
}

//新增历史输入
export function addHistory(data) {
  return request({
    url: request.apiModule.rdfm + '/structure/history',
    method: 'put',
    data
  })
}
//新增知识库输入
export function addRepo(data) {
  return request({
    url: request.apiModule.rdfm + '/structure/repository',
    method: 'put',
    data
  })
}

// 添加结构，功能。。。
export function addNode(data) {
  return request({
    url: request.apiModule.rdfm + '/structure',
    method: 'post',
    data
  })
}

// 结构：多级添加
export function addMultiStruNode(data) {
  return request({
    url: request.apiModule.rdfm + '/structure/multilevel',
    method: 'post',
    data
  })
}

// 结构：多级元素添加
export function addMultiElementNode(data) {
  return request({
    url: request.apiModule.rdfm + '/structure/multilevel/ele',
    method: 'post',
    data
  })
}

// 添加上级
export function addSuperiorStructure(id) {
  return request({
    url: request.apiModule.rdfm + '/structure/superior',
    method: 'post',
    data: { id: id }
  })
}

//删除根节点
export function delRoot(id) {
  return request({
    url: request.apiModule.rdfm + '/structure/root',
    method: 'delete',
    data: { id: id }
  })
}

// 获取右侧的结构树
export function getFailTree(params) {
  return new Promise(function (resolve, reject) {
    resolve(MockData_r);
  });
  return request({
    url: request.apiModule.rdfm + '/structure/tree/right',
    method: 'get',
    params
  })
}

// 删除节点
export function delNode(id) {
  return request({
    url: request.apiModule.rdfm + '/structure',
    method: 'delete',
    data: { id: id }
  })
}

//获取属性初始Data
export function getAttr(params) {
  return request({
    url: request.apiModule.rdfm + '/strucdetail',
    method: 'get',
    params
  })
}

//修改组件名称
export function changeNodeName(data) {
  return new Promise(function(resolve, reject) {
    // resolve(data.structureName);
    let data = {
      message: "修改成功！"
    }
    resolve(data);
  })
  return request({
    url: request.apiModule.rdfm + '/strucdetail/name',
    method: 'put',
    data
  })
}

// 修改节点属性
export function editNode(data) {
  return request({
    url: request.apiModule.rdfm + '/strucdetail',
    method: 'put',
    data
  })
}

// 添加现行/优化措施
export function addMeas(data) {
  return request({
    url: request.apiModule.rdfm + '/structure/measure',
    method: 'post',
    data
  })
}

// 新增功能网关联信息
export function addFuncNet(data) {
  return request({
    url: request.apiModule.rdfm + '/function/net',
    method: 'post',
    data
  })
}

//节点上下移动
export function moveNode(data) {
  return request({
    url: request.apiModule.rdfm + '/structure/move',
    method: 'put',
    data
  })
}

//节点上下移动
export function paste(data) {
  return request({
    url: request.apiModule.rdfm + '/structure/paste',
    method: 'put',
    data
  })
}

// 获取当前节点的功能网信息
export function getFuncNet(structureId) {
  return new Promise(function (resolve, reject) {
    resolve(data.funcNet);
  });
  return request({
    url: request.apiModule.rdfm + '/function/net/' + structureId,
    method: 'get'
  })
}

// 获取可选择的下级结构
export function getFuncNetChildrenStruList(structureId) {
  return request({
    url: request.apiModule.rdfm + '/function/net/children/' + structureId,
    method: 'get'
  })
}

// 获取可选择的上级结构
export function getFuncNetParentStruList(structureId) {
  return request({
    url: request.apiModule.rdfm + '/function/net/parent/' + structureId,
    method: 'get'
  })
}

// 获取所选择节点下功能结构信息
export function getFuncNetStruList(structureId) {
  return request({
    url: request.apiModule.rdfm + '/function/net/structure/' + structureId,
    method: 'get'
  })
}

// 删除节点
export function delFuncNetNode(data) {
  return request({
    url: request.apiModule.rdfm + '/function/net',
    method: 'delete',
    data
  })
}

//转换节点类型
export function changeNodeType(structureId) {
  return request({
    url: request.apiModule.rdfm + '/structure/type',
    method: 'put',
    data: { id: structureId }
  })
}

// 新增失效网关联信息
export function addFailNet(data) {
  return request({
    url: request.apiModule.rdfm + '/fault/net',
    method: 'post',
    data
  })
}


export function getRiskFailNet(structureId) {
  return new Promise(function (resolve, reject) {
    resolve(data.failNet);
  });
  return request({
    url: request.apiModule.rdfm + '/fault/net/' + structureId,
    method: 'get'
  })
}

// 获取失效节点的功能网信息
export function getFailNet(structureId) {
  return new Promise(function (resolve, reject) {
    resolve(data.failNet);
  });
  return request({
    url: request.apiModule.rdfm + '/fault/net/' + structureId,
    method: 'get'
  })
}

// 获取失效网可选择的下级结构
export function getFailNetChildrenStruList(structureId) {
  return request({
    url: request.apiModule.rdfm + '/fault/net/children/' + structureId,
    method: 'get'
  })
}

// 获取失效网可选择的上级结构
export function getFailNetParentStruList(structureId) {
  return request({
    url: request.apiModule.rdfm + '/fault/net/parent/' + structureId,
    method: 'get'
  })
}

// 获取失效网所选择节点下功能结构信息
export function getFailNetStruList(structureId) {
  return request({
    url: request.apiModule.rdfm + '/fault/net/structure/' + structureId,
    method: 'get'
  })
}

// 删除失效网节点
export function delFailNetNode(data) {
  return request({
    url: request.apiModule.rdfm + '/fault/net/',
    method: 'delete',
    data
  })
}

// 获取接口连线信息
export function getChartConnect(params) {
  return request({
    url: request.apiModule.rdfm + '/chartmap/chartConnect',
    method: 'get',
    params
  })
}

// 获取合并列表
export function getMergeList(params) {
  return request({
    url: request.apiModule.rdfm + '/structure/merger',
    method: 'get',
    params
  })
}

// 合并
export function addMerge(data) {
  return request({
    url: request.apiModule.rdfm + '/structure/merger',
    method: 'post',
    data
  })
}

//升级
export function addUpper(structureId) {
  return request({
    url: request.apiModule.rdfm + '/structure/upper',
    method: 'put',
    data: { id: structureId }
  })
}
