import ajax from '../util'

/**
 * 删除实体类
 * @param opts
 */
function delEntityClass (id) {
  return ajax({
    method: 'post',
    url: '/entcls/del/{id}',
    path: {
      id: id
    }
  })
}

/**
 * 新增实体类
 * @param1 entClsName
 * @param2 entClsType
 * @param3 pid
 */
function addEntityClass (data) {
  return ajax({
    method: 'post',
    url: '/entcls/add',
    data: {
      entClsName: data.entClsName,
      pid: data.pid,
      entClsMemo: data.entClsMemo,
      entClsIcon: data.entClsIcon,
      backGroundColor:data.backGroundColor
      
    }
  })
}

/**
 * 获取所有实体类列表
 */
function getAllEntityClass (isIcon) {
  return ajax({
    method: 'get',
    url: '/entcls',
    data: {
      isIcon: isIcon
    }
  })
}

/**
 * 获取所有根实体类列表
 */
// /graph/entcls/root/tree
 function getAllEntclsRootTree (){
   return ajax({
     method: 'get',
     url: '/entcls/root/tree',
   })
 }

/**
 * 获取单个实体类
 * @param id 实体类id
 */
function getEntityClass (id) {
  return ajax({
    method: 'get',
    url: '/entcls/{id}',
    path: {
      id: id
    }
  })
}

/**
 * 实体类修改接口
 * @param type
 * @param id
 * @param name
 * @param entClsMemo
 * @param backGroundColor
 * @returns {*}
 */
function updateEntityClass (type, id, name, entClsMemo, entClsIcon,backGroundColor) {
  return ajax({
    method: 'post',
    url: '/entcls/update',
    data: {
      entClsAllowAttrType: type,
      entClsID: id,
      entClsName: name,
      entClsMemo: entClsMemo ? entClsMemo : '',
      entClsIcon: entClsIcon,
      backGroundColor: backGroundColor
    }
  })
}

/**
 * OWL文件导入
 * @param file
 * @param userCode
 * @returns {*}
 */
function owlFileImport (file) {
  return ajax({
    method: 'post',
    url: '/owl/file/import',
    headers: {'Content-Type': 'multipart/form-data'},
    data: {
      file
    }
  })
}

/**
 * oWL导出
 * @param id
 * @returns {*}
 */
function owlFileExport (id) {
  return ajax({
    method: 'get',
    url: '/owl/file/export',
    data: {
      entClsIDs: id
    }
  })
}

/**
 * 实体类树懒加载接口
 * @param id
 * @returns {*}
 */
function entClsTreeLazy (id) {
  return ajax({
    method: 'get',
    url: '/entcls/tree',
    data: {
      entClsID: id
    }
  })
}

/**
 * 根据实体类节点获取当前实体类节点的所有父节点
 * @param id
 * @returns {*}
 */
function getEntClsParents (id) {
  return ajax({
    method: 'get',
    url: '/entcls/parents',
    data: {
      entClsID: id
    }
  })
}

/**
 *待审属性类查找接口
 * @param id
 * @returns {*}
 */
function getEntClsNoneList (id) {
  return ajax({
    method: 'post',
    url: '/attrcls/none/list',
    data: {
      entClsID: id
    }
  })
}

/**
 *attrcls/none/merge
 * 属性类合并接口
 * @param id
 * @returns {*}
 **/
function getEntClsNoneMerge (data) {
  return ajax({
    method: 'post',
    url: '/attrcls/none/merge',
    headers: {'Content-Type': 'application/json;charset=UTF-8'},
    data: data,
    json: true
  })
}

/**
 *attrcls/none/move
 * NONE属性类迁移接口
 * @attrClsID  id
 * @mergeAttrClsIDs  {*}
 **/

function getEntClsNoneMmove (data) {
  return ajax({
    method: 'post',
    url: '/attrcls/none/move',
    // headers: {'Content-Type': 'application/json;charset=UTF-8'},
    data: data,
    // json: true
  })
}

/**
 * 待审属性调整保存接口
 * @param data
 * @returns {*}
 */
function saveAttrNoneAdjust (data) {
  return ajax({
    method: 'post',
    url: '/attr/none/adjust',
    headers: {'Content-Type': 'application/json;charset=UTF-8'},
    data: data,
    json: true
  })
}

/**
 *
 实体类添加自定义属性类
 * @param data
 * @returns {*}
 */
function addPublicAttrCls (data) {
  return ajax({
    method: 'post',
    url: '/entcls/add/public/attrcls',
    data: data
  })
}

/**
 * 获取编排ID
 * @param entClsId
 * @returns {*}
 */
function getFlowId (entClsId) {
  return ajax({
    method: 'get',
    url: '/neural/flow',
    data: {
      entClsId
    }
  })
}

/**
 * 获取编排ID
 * @param entClsID
 * @returns {*}
 */
function getEntClsPrefixList (entClsID) {
  return ajax({
    method: 'get',
    url: '/entcls/prefix/tree',
    data: {
      entClsID
    }
  })
}

/**
 * 获取编排ID
 * @param entClsID
 * @param entClsPrefix
 * @returns {*}
 */
function updateEntClsPrefix (entClsID, entClsPrefix) {
  return ajax({
    method: 'post',
    url: '/entcls/prefix/update',
    data: {
      entClsID,
      entClsPrefix
    }
  })
}

/**
 * 保存生成规则
 * @param entClsID
 * @param entClsConfig
 * @returns {*}
 */
function updateEntClsConfig (entClsID, entClsConfig) {
  return ajax({
    method: 'post',
    url: '/entcls/config/update',
    data: {
      entClsID,
      entClsConfig
    }
  })
}

/**
 * 清楚主库和模板库
 * @param message
 * @returns {*}
 */
function clearDatabase (message, clientType) {
  return ajax({
    method: 'post',
    url: '/vertex/all/drop',
    data: {
      message,
      clientType,
      noTimeout: true
    }
  })
}

export {
  addPublicAttrCls,
  saveAttrNoneAdjust,
  getEntClsNoneMmove,
  getEntClsNoneMerge,
  getEntClsNoneList,
  getEntClsParents,
  entClsTreeLazy,
  owlFileExport,
  owlFileImport,
  delEntityClass,
  addEntityClass,
  getAllEntityClass,
  getEntityClass,
  updateEntityClass,
  getFlowId,
  getAllEntclsRootTree,
  getEntClsPrefixList,
  updateEntClsPrefix,
  updateEntClsConfig,
  clearDatabase
}
