import ajax from '../util'

/**
 * 获得指定实体类为起点的所有关系类列表
 * @param id
 * @returns {*}
 */
function getAllRelationClassList (id, entClsType) {
  return ajax({
    method: 'get',
    url: '/relcls/{id}/list',
    path: {
      id: id
    },
    data: {
      entClsType: entClsType,
    }
  })
}

/**
 * 删除关系类
 * @param id
 * @returns {*}
 */
function deleteRelationClass (id) {
  return ajax({
    method: 'post',
    url: '/relcls/del/{id}',
    path: {
      id: id
    }
  })
}

/**
 * 通过名称获取所有关系类列表
 * @param name
 * @returns {*}
 */
function getAllRelationClassListByName (name, isModel, current, size) {
  return ajax({
    method: 'get',
    url: '/relcls/list',
    data: {
      name: name,
      current,
      size,
      isModel
    }
  })
}

/**
 * 修改一个关系类名
 * @param data
 * @returns {*}
 */
function editRelationClass (data) {
  return ajax({
    method: 'post',
    url: '/relcls/update',
    data: data
  })
}

/**
 * 添加一个关系类
 * @param data
 * @returns {*}
 */
function addRelationClass (data) {
  return ajax({
    method: 'post',
    url: '/relcls/add',
    data: data
  })
}

/**
 * 新建实体关系
 * @param data
 * @returns {*}
 */
function addEntityRelation (data) {
  return ajax({
    method: 'post',
    url: '/rel/add',
    data: data
  })
}

/**
 * 删除实体关系
 * @param relID, isModel
 * @returns {*}
 */
function deleteEntityRelation (relID, isModel) {
  return ajax({
    method: 'post',
    url: '/rel/del/{id}',
    path: {
      id: relID
    },
    data: {
      id: relID,
      isModel
    }
  })
}

/**
 * 查找所有关系类
 * */
function getAllRelationClass () {
  return ajax({
    method: 'post',
    url: '/relcls/getall'
  })
}

/**
 * 批量新增实体关系
 * */
function addRelBatch (data) {
  return ajax({
    method: 'post',
    url: '/rel/add/batch',
    data: data
  })
}

/**
 * 查询此关系类所指向实体类还未有关联的实体列表
 * @param relClsId direction isModel current size
 * @returns {*}
 */
function getRelclsUnpoint(relClsId, direction, entId, isModel, current, size) {
  return ajax({
    method: 'get',
    url: '/relcls/{direction}/{relClsId}/unpoint/{entId}',
    data: {
      current,
      size,
      isModel
    },
    path: {
      direction,
      relClsId,
      entId
    }
  })
}

/**
 * 查询此关系类所指向实体类还未有关联的实体列表(带属性类)
 * @param relClsId direction isModel current size
 * @returns {*}
 */
function getRelclsEnt(relClsId, direction, entId, isModel, entName, current, size) {
  return ajax({
    method: 'get',
    url: '/relcls/{direction}/{relClsId}/ent/{entId}',
    data: {
      entName,
      current,
      size,
      isModel
    },
    path: {
      direction,
      relClsId,
      entId
    }
  })
}

/**
 * 批量编辑实体关系
 * */
function editRelBatch (data) {
  return ajax({
    method: 'post',
    url: '/relattr/update/batch',
    data: data
  })
}

export {
  addRelationClass,
  getAllRelationClassList,
  deleteRelationClass,
  getAllRelationClassListByName,
  editRelationClass,
  deleteEntityRelation,
  addEntityRelation,
  getAllRelationClass,
  addRelBatch,
  getRelclsUnpoint,
  editRelBatch,
  getRelclsEnt
}
