import {
	httpUrlFormat,
	ajaxCarryAuthorization,ajaxSync
} from '@/utils/httpUtils.js'


import { ApiVersion,AppVersion } from '@/config/baseConfig.js'

const headerVersion = {
	'API-Version': ApiVersion(),
	'APP-Version':AppVersion()
}


const _flag = 'apiBaseUrl' // 请求的api空间

const apiUrl = {
	'product': httpUrlFormat('/product', _flag),//商品分页
	'categories': httpUrlFormat('/product/categories', _flag),//商品分类
	'rollingImgs': httpUrlFormat('/rolling_imgs', _flag),//商品分类
	'favorItem': httpUrlFormat('/user/favor_item', _flag),//收藏
	'deliveryFee': httpUrlFormat('/product/delivery_fee', _flag),//运费
	'favorItemProduct': httpUrlFormat('/user/favor_item_product', _flag),//运费
	'searchHistoryRecommend': httpUrlFormat('/search_history/recommend', _flag),//搜索推荐
	'searchHistoryPersonal': httpUrlFormat('/search/history/personal', _flag),//搜索推荐
	'orderBoxRecordCount': httpUrlFormat('/order/box_record_count', _flag),//盲盒统计
	'carriageRule': httpUrlFormat('/misc/carriage/rule', _flag),
	'carriageGetRule': httpUrlFormat('/misc/carriage/get', _flag),
	'tagsChannelApi': httpUrlFormat('/product/tags/channel', _flag),
	'productChannelApi': httpUrlFormat('/product/channel', _flag),
	'productRecommendChannel': httpUrlFormat('/product/product/recommend/channel', _flag),
	'productChannelPointApi': httpUrlFormat('/product/channel/points', _flag),
	
	'tagsPointApi': httpUrlFormat('/misc/product/points/tag', _flag),
	
}


// 渠道商品tag
export function tagsChannelApi(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		url: apiUrl.tagsChannelApi,
		method: 'GET',
		data: data
	})
}
// 渠道商品
export function productChannelApi(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.productChannelApi,
		method: 'GET',
		data: data
	})
}

export function productRecommendChannel(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		url: apiUrl.productRecommendChannel,
		method: 'GET',
		data: data
	})
}

// 渠道商品积分筛选
export function productChannelPointApi(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.productChannelPointApi,
		method: 'GET',
		data: data
	})
}

// 运费
export function deliveryFee() {
	return ajaxCarryAuthorization({
		header: headerVersion,
		url: apiUrl.deliveryFee,
		method: 'GET',
	})
}
export function product(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.product,
		method: 'GET',
		data: data
	})
}
// 商品分类
export function categories(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.categories,
		method: 'GET',
		data: data
	})
}
// 商品详情
export function productDetail(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: httpUrlFormat(`/product/${data}`, _flag),
		method: 'GET',
	})
}
// 商城轮播
export function rollingImgs(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.rollingImgs,
		method: 'GET',
	})
}
// 收藏列表
export function favorItemList(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		url: apiUrl.favorItem,
		method: 'GET',
		data	
	})
}
// 收藏
export function favorItem(data) {
	const headerObj = {...headerVersion,'Content-Type': 'application/x-www-form-urlencoded'}
	return ajaxCarryAuthorization({
		header: headerObj,
		url: apiUrl.favorItem,
		method: 'POST',
		data
	})
}

// 删除收藏
export function delFavorItem(ids) {
	const headerObj = {...headerVersion,'Content-Type': 'application/x-www-form-urlencoded'}
	return ajaxCarryAuthorization({
		header: headerObj,
		// url: apiUrl.cart_item,
		url: httpUrlFormat(`/user/favor_item${ids}`, _flag),
		method: 'DELETE'
	})
}
// 删除商品详情收藏
export function favorItemProduct(data) {
	const headerObj = {...headerVersion,'Content-Type': 'application/x-www-form-urlencoded'}
	return ajaxCarryAuthorization({
		header: headerObj,
		// url: apiUrl.cart_item,
		url: httpUrlFormat(`/user/favor_item_product${data}`, _flag),
		method: 'DELETE',
		// data: data
	})
}
// 搜索推荐
export function searchHistoryRecommend(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.searchHistoryRecommend,
		method: 'GET',
		data
	})
}
// 搜索历史
export function searchHistoryPersonal(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.searchHistoryPersonal,
		method: 'GET',
		data
	})
}
// 删除搜索历史
export function delSearchHistoryPersonal() {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.searchHistoryPersonal,
		method: 'DELETE',
	})
}
// 盲盒统计
export function orderBoxRecordCount(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.orderBoxRecordCount,
		method: 'GET',
		data
	})
}
export function carriageRule(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.carriageRule,
		method: 'GET',
		data
	})
}
export function carriageGetRule(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.carriageGetRule,
		method: 'GET',
		data
	})
}

export function tagsPointApi(data) {
	return ajaxCarryAuthorization({
		header: headerVersion,
		// header: {'Content-Type': 'application/x-www-form-urlencoded'},
		url: apiUrl.tagsPointApi,
		method: 'GET',
		data
	})
}

