package com.kym.miniapp.controller;

import com.kym.common.R;
import com.kym.entity.queryParams.CouponQueryParam;
import com.kym.service.CouponService;
import com.kym.service.UserCouponService;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户优惠券 前端控制器
 * </p>
 *
 * @author skyline
 * @since 2024-04-29
 */
@RestController
@RequestMapping("/coupon")
public class CouponController {

    private final CouponService couponService;

    private final UserCouponService userCouponService;

    public CouponController(CouponService couponService, UserCouponService userCouponService) {
        this.couponService = couponService;
        this.userCouponService = userCouponService;
    }

    /**
     * 获取当前站点可以领取的优惠券列表
     *
     * @param params
     * @return
     */
    @GetMapping(value = "/listAvailableCoupons")
    public R<?> listAvailableCoupons(@ModelAttribute CouponQueryParam params) {
        return R.success(couponService.listAvailableCoupons(params));
    }

    /**
     * 领取优惠券
     *
     * @param couponId
     * @return
     */
    @GetMapping(value = "/collectCoupon")
    public R<?> collectCoupon(@RequestParam("couponId") Long couponId) {
        userCouponService.collectCoupon(couponId);
        return R.success();
    }

}
