import ajax from '../util'

/**
 * 通过id获取关系属性
 */
function getRelationAttr (path) {
  return ajax({
    method: 'get',
    url: '/relcls/{id}/attrs',
    path: {
      id: path
    },
    data: {
      id: path
    }
  })
}

/**
 * 新增关系属性
 */
function addRelationAttr (data) {
  return ajax({
    method: 'post',
    url: '/relcls/attrcls/add',
    path: {},
    data: {
      relClsID: data.relClsID,
      attrUnit: data.attrUnit,
      attrClsName: data.attrClsName,
      attrClsMemo: data.attrClsMemo,
      valueType: data.valueType
    }
  })
}

/**
 * 修改关系属性
 * @param data
 */
function updateRelationAttr (data) {
  return ajax({
    method: 'post',
    url: '/relattr/update',
    path: {},
    data: {
      relID: data.relID, // 关系id,新加
      attrClsID: data.attrClsID,// *属性类ID
      attrMemo: data.attrMemo,// 属性描述
      attrValue: data.attrValue,// 属性值
      entID: data.entID// 实体ID
    }
  })
}

/**
 * 修改关系类属性
 */
function updateRelationClassAttr (data) {
  return ajax({
    method: 'post',
    url: '/relcls/attrcls/update',
    path: {},
    data: {
      attrUnit: data.attrUnit,
      attrClsID: data.attrClsID,
      attrClsMemo: data.attrClsMemo,
      attrClsName: data.attrClsName,
      valueType: data.valueType
    }
  })
}

/**
 * 删除关系类下的关系属性
 */
function delRelationAttr (path) {
  return ajax({
    method: 'post',
    url: '/relcls/attrcls/del/{id}',
    path: {
      id: path
    },
    data: {}
  })
}

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

export {
  getRelationAttr,
  addRelationAttr,
  updateRelationAttr,
  updateRelationClassAttr,
  delRelationAttr,
  getRelationListByEntityClassId
}
