package com.yc.ship.module.marketing.controller.admin.couponProduct;


import com.yc.ship.framework.common.pojo.CommonResult;
import com.yc.ship.module.marketing.controller.admin.couponProduct.vo.CouponProductRespVo;
import com.yc.ship.module.marketing.controller.admin.couponProduct.vo.CouponProductSaveReqVo;
import com.yc.ship.module.marketing.service.couponProduct.CouponProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.yc.ship.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 优惠券关联产品")
@RestController
@RequestMapping("/marketing/couponProduct")
@Validated
public class CouponProductController {

    @Resource
    private CouponProductService couponProductService;


    @PostMapping("/create")
    @Operation(summary = "创建优惠券关联产品")
    @PreAuthorize("@ss.hasPermission('marketing:couponProduct:relation')")
    public CommonResult<Boolean> createCouponProduct(@RequestBody @Validated CouponProductSaveReqVo reqVO) {
        return success(couponProductService.createCouponProduct(reqVO));
    }

    @GetMapping("/getByCouponId")
    @Operation(summary = "获得优惠券关联产品")
    @PreAuthorize("@ss.hasPermission('marketing:couponProduct:relation')")
    public CommonResult<CouponProductRespVo> getByCouponId(@RequestParam("id") Long couponId) {
        return success(couponProductService.getCouponProductByCouponId(couponId));
    }

}