import {
	findCoupon
} from '@/common/api/market/coupon.js';
import * as UTILS from '@/utils/goods-utils.js'
export async function returnHasCouponCanUse(args) {
	const {
		goodsOrderPrice,
		dinnerType,
		shopId,
		shopInfo,
		shopUserId,
		allGoods,
		user
	} = args
	const res = await findCoupon({
		shopUserId,
	});
	if(!res||res.length<=0){
		return false
	}
	console.log('returnHasCouponCanUse:goodsOrderPrice',goodsOrderPrice);
	console.log('returnHasCouponCanUse:allGoods',allGoods);
	const canDikouGoodsArr = UTILS.returnCanDikouGoods(allGoods, [], user);
	for (let i = 0; i < res.length; i++) {
		const coupon = res[i]
		const canuseResult = UTILS.returnCouponCanUse({
			canDikouGoodsArr,
			coupon,
			goodsOrderPrice,
			user,
			selCoupon: [],
			shopInfo
		})
		const {
			canUse,
			reason
		} = canuseResult
		if (canUse) {
			return true
		} 
	}
	
	return false
	

}