const db = uniCloud.database({
  spaceId: 'tcb-nikbzhlwnpd5n913e1c5e-50f4bbo'
})
 
 let cloudRulesApiFun = function(vm){
 	
	/* 查询所有产品 废弃*/
	let getAllProduct = async () => await db.collection("product").get();
	
 	/* 查询产品下的品牌 {product_code:"P0001"} 废弃*/
 	let getBrand = async (params = {}) => await db.collection("brand").where(params).get();
	
	/* 查询规范项目 {product_code:"P0001"} 废弃*/
	let getstandard = async (params = {}) => await db.collection("standard").where(params).get();
	
	/* 查询分组规范项目 废弃*/
	let getGroupStandard = async (params = {}) => await uniCloud.callFunction({name: 'getGroupStandard', data: params});
	
	/* 查询类别数据 */
	let getClassifyDictionary = async () => await db.collection("dictionary").where({"type":"classify"}).get()
	
	/* 查询有数据的系统 或者 品牌 数据   {"classify_id":"","system_id":"","field":"system_id|brand_id"}*/
	let getRelationDictionary = async (params = {}) => await uniCloud.callFunction({name: 'getRelationDictionary', data: params});
	
	let getRelationDictionaryV2 = async () => await uniCloud.callFunction({name: 'getRelationDictionaryV2'});
	
	/* 查询规范 根据 分类、系统、品牌   {"token":"", "classify_id":"","system_id":"","brand_id":""} */
	let getGroupStandardV2 = async (params = {}) => await uniCloud.callFunction({name: 'getGroupStandardV2', data: params});
	
	/* 保存图片   {"token":"", "standardId":"", "url":""} */
	let saveImage = async (params = {}) => await uniCloud.callFunction({name: 'saveImage', data: params});
	
	/* 获取用户水印，首次返回默认水印   {"token":"", "systemId":""} */
	let getUserWatermark =  async (params = {}) => await uniCloud.callFunction({name: 'getUserWatermark', data: params});
	
	/* 保存用户水印配置  {"token":"", "watermark": getUserWatemark返回的数据} */
	let saveUserWatermark =  async (params = {}) => await uniCloud.callFunction({name: 'saveUserWatermark', data: params});
 	
 	const rulesApi = {
		getAllProduct,
 		getBrand,
		getstandard,
		getGroupStandard,
		// 新接口
		getClassifyDictionary,
		getRelationDictionary,
		getRelationDictionaryV2,
		getGroupStandardV2,
		saveImage,
		getUserWatermark,
		saveUserWatermark
 	}
 	return rulesApi
 }
 
 module.exports =  {
 	cloudRulesApiFun
}