import ajax from '../util'

/**
 * 通过实体id获取实体属性
 * @param opts
 * @id:id
 */

function getEntityAttrById (id, data, isModel) {
  return ajax({
    method: 'get',
    url: '/ent/{id}/attrs',
    path: {
      id: id
    },
    data: {
      attrType: data.attrType,
      id: id,
      isModel
    }
  })
}

/**
 * 编辑实体属性
 * @param opts
 * @id:id
 */
function updateEntityAttr (data) {
  return ajax({
    method: 'post',
    url: 'entattr/update',
    data: {
      attrID: data.attrID,
      attrClsID: data.attrClsID,
      attrMemo: data.attrMemo,
      attrType: data.attrType,
      attrValue: data.attrValue,
      entID: data.entID
    }
  })
}

/**
 * 通过实体id获取关系属性
 * @entId:实体id
 * @relId:关系id
 */

function getRelationAttrById (path, entType) {
  return ajax({
    method: 'get',
    url: 'relattr/{id}/list',
    path: {
      id: path
    },
    data: {
      id: path,
      entType: entType
    }
  })
}

/**
 * 通过实体类,属性,指标能力id查询列表
 * @param entClsId
 * @param attrClsId
 * @param abilityId
 * @returns {*}
 */
function getTargetList (entClsId, attrClsId, abilityId) {
  return ajax({
    method: 'get',
    url: '/sysmgt/list',
    data: {
      entClsId: entClsId,
      attrClsId: attrClsId,
      abilityId: abilityId
    }
  })
}

/**
 * 获得指标能力树
 * @returns {*}
 */
function getTargetAbilityTree () {
  return ajax({
    method: 'get',
    url: '/sysmgt/ability/tree',
    path: {}
  })
}

/**
 * 根据能力abilityId获取单个算法详情
 * @returns {*}
 */
function getAlgorithmDetail (abilityId) {
  return ajax({
    method: 'get',
    url: '/sysmgt/flow',
    data: {
      abilityId: abilityId
    }
  })
}

/**
 * 数组list参数保存指标
 * @param abilityParam
 * @returns {*}
 */
function saveTargetList (abilityParam) {
  return ajax({
    method: 'post',
    url: '/sysmgt/add/array',
    headers: {'Content-Type': 'application/json;charset=UTF-8'},
    data: abilityParam,
    json: true
  })
}

/**
 * 获得指标树能力id
 * @param entClsId
 * @param attrClsId
 * @returns {*}
 */
function getAbilityId (entClsId, attrClsId) {
  return ajax({
    method: 'get',
    url: '/sysmgt/getability',
    data: {
      entClsId: entClsId,
      attrClsId: attrClsId
    }
  })
}

/**
 * 运行测试
 * @param entId
 * @param attrClsId
 * @returns {*}
 */
function runFlow (entId, attrClsId, isModel) {
  return ajax({
    method: 'post',
    url: '/sysmgt/run/flow',
    data: {
      entId: entId,
      attrClsId: attrClsId,
      isModel
    }
  })
}

/**
 * 删除属性值
 * @param attrID
 * @returns {*}
 */
function deleteAttrValue (attrID) {
  return ajax({
    method: 'post',
    url: '/attr/del',
    data: {
      attrID: attrID
    }
  })
}

export {
  deleteAttrValue,
  runFlow,
  getAbilityId,
  saveTargetList,
  getEntityAttrById,
  updateEntityAttr,
  getRelationAttrById,
  getTargetList,
  getTargetAbilityTree,
  getAlgorithmDetail
}
