import ajax from '../util'

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

function getAttrClassById (entClsID, data) {
  return ajax({
    method: 'get',
    url: '/attrcls/{id}/list',
    path: {
      id: entClsID
    },
    data: {
      id: entClsID,
      attrType: data
    }
  })
}

/**
 * 通过实体类id获取属性类(新的，带出是否必填项)
 * @param opts
 * @id:id
 */

function getAttrClassById2 (entClsID, data) {
  return ajax({
    method: 'get',
    url: '/attrcls/notnull/{id}/list',
    path: {
      id: entClsID
    },
    data: {
      id: entClsID
    }
  })
}

/**
 * 新增属性类
 * @param opts
 * path:''
 * data:新增参数{}
 */
function addAttrClass (data) {
  return ajax({
    method: 'post',
    url: '/attrcls/add',
    data: {
      attrClsName: data.attrClsName,
      attrUnit: data.attrUnit,
      entAndAttrType: data.attrType,
      entClsID: data.entClsID,
      attrClsMemo: data.attrClsMemo,
      valueType: data.valueType,
      domainKey: data.domainKey,
      isPublic: data.isPublic,
      maxValue: data.maxValue,
      minValue: data.minValue,
      notNull: data.notNull
    }
  })
}

/**
 * 修改属性类
 * @param opts
 * path:''
 * data:修改的参数{entClsID,entClsName,pid}
 */
function updateAttrClass (data) {
  return ajax({
    method: 'post',
    url: '/attrcls/update',
    data: {
      attrClsID: data.attrClsID,
      attrClsName: data.attrClsName,
      attrUnit: data.attrUnit,
      attrClsMemo: data.attrClsMemo,
      valueType: data.valueType,
      attrType: data.attrType,
      domainKey: data.domainKey,
      isPublic: data.isPublic,
      maxValue: data.maxValue,
      minValue: data.minValue,
      notNull: data.notNull
    }
  })
}

/**
 * 删除属性类
 * @param opts
 * path:删除的id
 * data:‘’
 */
function delAttrClass (entClsID) {
  return ajax({
    method: 'post',
    url: '/attrcls/del/{id}',
    path: {
      id: entClsID
    },
    data: {
      id: entClsID
    }
  })
}

/**
 * 批量删除属性类
 * @param attrClsIDs
 * path:删除的id
 * data:‘’
 */
function delAttrClassList (attrClsIDs) {
  return ajax({
    method: 'post',
    url: '/attrcls/del/batch',
    data: {
      attrClsIDs
    }
  })
}

/**
 * 批量更新属性类
 * @param attrClsId
 * @param attrValue
 * @param entClsId
 * @param isModel
 */
function updatePublicAttrClass (attrClsId, attrValue, entClsId, isModel) {
  return ajax({
    method: 'post',
    url: '/attrcls/public/update/attrvalue',
    data: {
      attrClsId,
      attrValue,
      entClsId,
      isModel
    }
  })
}

export {
  getAttrClassById,
  getAttrClassById2,
  addAttrClass,
  updateAttrClass,
  delAttrClass,
  delAttrClassList,
updatePublicAttrClass
}
