package com.czg.controller.user;

import com.czg.account.entity.ShopActivateCouponRecord;
import com.czg.account.service.ShopCouponService;
import com.czg.account.vo.UserCouponVo;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.utils.AssertUtil;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店铺优惠券
 *
 * @author ww
 * @description
 */

@RestController
@RequestMapping("/user/coupon")
public class UserShopCouponController {
    @Resource
    private ShopCouponService couponService;

    /**
     * 通过用户Id 查找优惠券
     *
     * @param status 0 未使用 1已使用 2已过期
     */
    @GetMapping("/findByUserId")
    public CzgResult<Page<ShopActivateCouponRecord>> findByUserId(
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false) Long shopId) {
        return CzgResult.success(couponService.find(StpKit.USER.getLoginIdAsLong(), shopId, status));
    }

    /**
     * 生成订单后使用
     * 通过用户Id 查找优惠券
     *
     * @param shopUserId 店铺用户Id
     */
    @GetMapping("/findCoupon")
    public CzgResult<List<UserCouponVo>> findCoupon(@RequestHeader String shopId, @RequestParam Long shopUserId, @RequestParam(required = false) Integer type) {
        AssertUtil.isBlank(shopId, "店铺Id不能为空");
        return CzgResult.success(couponService.findCoupon(Long.parseLong(shopId), shopUserId, type));
    }
}
