import ajax from '../util'

/**
 * 根据实体类id获取实体列表
 * @param id
 * @returns {*}
 */
function getEntityListByEntityClassId(id, data) {
	return ajax({
		method: 'get',
		url: '/ent/{id}/list',
		path: {
			id: id,
		},
		data: {
			id: id,
		},
	})
}

/**
 * 删除实体
 * @param id
 * @returns {*}
 */
function delEntityById(id, isModel) {
	return ajax({
		method: 'post',
		url: '/ent/del/ids',
		data: {
			ids: id,
			isModel,
		},
	})
}

// 原有的删除接口，没有调用成功
// function delEntityById (id) {
//   return ajax({
//     method: 'post',
//     url: '/ent/del/{id}',
//     path: {
//       id:id
//     }
//   })
// }

/**
 * 批量删除实体
 * @param ids
 * @returns {*}
 */
function delEntityByIds(ids) {
	return ajax({
		method: 'post',
		url: '/ent/del/ids',
		data: {
			ids: ids,
		},
	})
}

/**
 * 添加实体
 * @param entClsID
 * @param entName
 * @returns {*}
 */
function addEntity(
	entClsID,
	entName,
	entMemo,
	entIcon,
	notNullAttrVOList,
	isModel
) {
	return ajax({
		method: 'post',
		url: '/ent/add',
		headers: { 'Content-Type': 'application/json;charset=UTF-8' },
		data: {
			entClsID: entClsID,
			entMemo: entMemo,
			entName: entName,
			entIcon: entIcon,
			notNullAttrVOList: notNullAttrVOList, // 必填属性列表
			isModel,
		},
		json: true,
	})
}

/**
 * 根据实体id获取实体详情
 * @param id
 * @returns {*}
 */
function getEntityDetailById(id, isModel) {
	return ajax({
		method: 'get',
		url: '/ent/{id}',
		path: {
			id: id,
		},
		data: {
			isModel,
		},
	})
}

/**
 * 实体修改接口
 * @param entID
 * @param entName
 * @returns {*}
 */
function updateEntityName(entID, entName, entMemo, entIcon, isModel) {
	return ajax({
		method: 'post',
		url: '/ent/update',
		data: {
			entID: entID,
			entMemo: entMemo, // 可选择传不传
			entName: entName,
			entIcon: entIcon,
			isModel,
		},
	})
}

/**
 * 通过实体名字查询实体类
 * @param entName
 * @returns {*}
 */
function searchEntClsByEntName(entName) {
	return ajax({
		method: 'get',
		url: 'ent/search/entclses',
		data: {
			entName: entName,
		},
	})
}

/**
 *待审属性删除接口
 * @param attrClsID
 * @returns {*}
 */
function deleteAttrClassNone(attrClsID, isModel) {
	return ajax({
		method: 'post',
		url: '/attrcls/none/del/{attrClsID}',
		path: {
			attrClsID: attrClsID,
		},
		data: {
			attrClsID: attrClsID,
			isModel,
		},
	})
}

/**
 *待审属性新增属性
 * @param entID
 * @param attrValue
 * @param attrClsName
 * @param valueType
 * @returns {*}
 */
function addEntNoneAttr(data) {
	return ajax({
		method: 'post',
		url: '/attr/add/none',
		data: {
			entID: data.entID,
			attrClsMemo: data.attrClsMemo,
			attrClsName: data.attrClsName,
			attrUnit: data.attrUnit,
			attrValue: data.attrValue,
			valueType: data.valueType,
			isModel: data.isModel,
		},
	})
}

//

/**
 * 实体待审属性查找接口
 * @param entID
 * @returns {*}
 */
function getEntNoneList(entID, pagenum, pagesize, isModel) {
	return ajax({
		method: 'post',
		url: '/attr/none/list',
		data: {
			entID: entID,
			pagenum: pagenum,
			pagesize: pagesize,
			isModel,
		},
	})
}

/**
 * 待审属性类调整中的查询
 * @param attrClsID
 * @returns {*}
 */
function getAttrClassAdjustSearch(attrClsID) {
	return ajax({
		method: 'post',
		url: '/attrcls/none/attrs',
		data: {
			attrClsID: attrClsID,
		},
	})
}

/**
 * 待审属性名称修改接口
 * @param data
 * @returns {*}
 */
function updateAttrNoneName(data) {
	return ajax({
		method: 'post',
		url: '/attr/none/update',
		data: data,
	})
}

/**
 * 参照创建模板
 * @param entReferenceQuery : {
            "delEntIds": [
              "string"
            ],
            "entIcon": "string",
            "entMemo": "string",
            "entName": "string",
            "isModel": true,
            "modelId": "string",
            "suffix": "string"
          }
 * @returns {*}
 */
function addReferenceEnt(entReferenceQuery) {
	return ajax({
		method: 'post',
		url: '/ent/reference/add',
		data: entReferenceQuery,
	})
}

/**
 * 根据某一实体，关联出他的一定度数的数据
 * @param id, degree, delEntIds, direction, isModel, entClsIDs, relClsIDs
 * @returns {*}
 */
function getRelationEnt(
	id,
	degree,
	delEntIds,
	direction="BOTH",
	isModel,
	entClsIDs,
    entName,
	relClsIDs,
    limitNum=3,
    entConditionQueries=[]
) {
	return ajax({
		method: 'post',
		url: '/show/graph',
		data: {
			entId: id,
			degree,
			delEntIds,
			direction,
			isModel,
            entName,
			relClsIDs,
            limitNum,
            entConditionQueries: entConditionQueries
		},
        headers: { 'Content-Type': 'application/json;charset=UTF-8' },
		json: true,
	})
}
/* 

            let data = {
                degree: this.degreeCache,
                delEntIds: this.getDelEntIdsString(),
                direction: direction,
                entId: id,
                entName: name,
                relClsIDs: this.linkClassCache,
                limitNum: 3,
                isModel: false,
                entConditionQueries: entConditionQueries
            }
*/
function getChart(data) {
	return ajax({
		method: 'post',
		url: '/show/graph',
		data: data,
		headers: { 'Content-Type': 'application/json;charset=UTF-8' },
		json: true,
	})
}
/**
 * 根据实体类，获取关系类
 * @param id, degree, delEntIds, direction, isModel
 * @returns {*}
 */
function getRelationClsByEntCls(id) {
	return ajax({
		method: 'get',
		url: '/relcls/all/list/{id}',
		path: {
			id,
		},
	})
}

/**
 * 根据关系类获取树形
 * @param entId, relClsId, direction, isModel, current, size
 * @returns {*}
 */
function getRelationAttr(entId, relClsId, direction, isModel, current, size) {
	return ajax({
		method: 'get',
		url: '/entcls/{direction}/{relClsId}/{entId}',
		path: {
			entId,
			relClsId,
			direction,
		},
		data: {
			current,
			isModel,
			size,
		},
	})
}

/**
 * 保存基础属性/能力属性
 * @param data
 * @returns {*}
 */
function saveEntAttr(data) {
	return ajax({
		method: 'post',
		url: '/ent/update/batch',
		data: data,
	})
}

/**
 * 集成服务导出接口1
 * @param data
 * @returns {*}
 */
function exportUnionid() {
	return ajax({
		method: 'post',
		url: '/ent/batch/unionid',
		data: {
			noTimeout: true,
		},
	})
}

/**
 * 集成服务导出接口2
 * @returns {*}
 */
function exportOmsUpload() {
	return ajax({
		method: 'post',
		url: '/oms/media/upload',
		data: {
			noTimeout: true,
		},
	})
}

export {
	updateAttrNoneName,
	getAttrClassAdjustSearch,
	addEntNoneAttr,
	getEntNoneList,
	deleteAttrClassNone,
	searchEntClsByEntName,
	getEntityListByEntityClassId,
	delEntityById,
	addEntity,
	getEntityDetailById,
	updateEntityName,
	delEntityByIds,
	addReferenceEnt,
	getRelationEnt,
	getRelationClsByEntCls,
	getRelationAttr,
	saveEntAttr,
	exportUnionid,
	exportOmsUpload,
	getChart,
}
