import request from '@/utils/request'

/**
 * 加入购物车
 * @param data - 包含邮箱的参数
 * @param data.listingId - 商品ID
 * @param data.listingIds - 商品ID列表
 */
export const AddShoppingCart = (data, loading?: boolean) => {
	return request({
		url: '/buyer/buyer/cart/add',
		method: 'post',
		data,
		loading
	})
}

/**
 * 清空购物车
 */
export const ClearShoppingCart = (loading?: boolean) => {
	return request({
		url: '/buyer/buyer/cart/clear',
		method: 'delete',
		loading
	})
}

/**
 * 获取购物车列表
 * @param loading - 是否显示loading
 * @returns 购物车列表数据
 */
export const GetShoppingCartList = (loading?: boolean) => {
	return request({
		url: '/buyer/buyer/cart/list',
		method: 'get',
		loading
	})
}

/**
 * 从购物车移除商品
 * @param params - 包含邮箱的参数
 * @param params.listingId - 商品ID
 */
export const RemoveShoppingCartItem = (params, loading?: boolean) => {
	return request({
		url: '/buyer/buyer/cart/remove',
		method: 'delete',
		params,
		loading
	})
}

/**
 * 创建订单
 * @param { Array } data - 商品id数组
 * @param loading - 是否显示loading
 * @returns 
 */
export const CreateOrder = (data, loading?: boolean) => {
	return request({
		url: '/buyer/buyer/order/create',
		method: 'post',
		data,
		loading
	})
}

/**
 * 获取订单状态
 * @param { String } paymentId - 订单ID
 * @param loading - 是否显示loading
 * @returns 
 */
export const GetOrderStatus = (paymentId: string) => {
	return request({
		url: `/buyer/buyer/payment/status/${paymentId}`,
		method: 'get',
		loading: true,
	})
}
export const ORDER_STATUS = {
	PENDING: 0,//待支付
	SUCCESS: 1,//支付成功
	FAILED: 2,//支付失败
	CANCELED: 3,//已取消支付
	PARTIAL_REFUND: 4,//已部分退款
	FULL_REFUND: 5,//已全额退款
}
