package com.kym.admin.controller;

import com.kym.common.R;
import com.kym.entity.admin.Coupon;
import com.kym.entity.admin.queryParams.CouponQueryParam;
import com.kym.entity.admin.vo.CouponVo;
import com.kym.entity.admin.vo.UserCouponsIssueVo;
import com.kym.service.admin.CouponService;
import com.kym.service.miniapp.UserCouponService;
import org.springframework.web.bind.annotation.*;

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

    private final CouponService couponService;

    private final UserCouponService couponUserCouponService;

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


    /**
     * 优惠券列表查询
     *
     * @param
     * @return
     */
    @GetMapping("list")
    public R<?> listCoupon(@ModelAttribute CouponQueryParam params) {
        return R.success(couponService.listCoupon(params));
    }


    /**
     * 发放优惠券
     *
     * @param userCouponsIssue
     * @return
     */
    @PostMapping("issueCoupons")
    R<?> issueCoupons(@RequestBody UserCouponsIssueVo userCouponsIssue) {
        couponService.issueCoupons(userCouponsIssue);
        return R.success();
    }


    /**
     * 用户优惠券列表
     * @param params
     * @return
     */
    @GetMapping("listUserCoupons")
    R<?> listUserCoupons(@ModelAttribute CouponQueryParam params){
        return R.success(couponUserCouponService.listUserCoupons(params));
    }

}
