package cn.iocoder.yudao.module.custom.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.custom.entity.CustomerCoupon;
import cn.iocoder.yudao.module.custom.service.CustomerCouponService;
import cn.iocoder.yudao.module.custom.vo.CustomerCouponPageReqVO;
import cn.iocoder.yudao.module.custom.vo.CustomerCouponRespVO;
import cn.iocoder.yudao.module.custom.vo.CustomerCouponSaveReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
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 javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 用户卡券")
@RestController
@RequestMapping("/base/customer-coupon")
@Validated
public class CustomerCouponController {

    @Resource
    private CustomerCouponService customerCouponService;

    /**
     * 核销用户卡券
     *
     * @param saveReqVO CustomerCouponSaveReqVO实体
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 15:58 2024/9/23
     **/
    @PostMapping("/couponVerification")
    @Operation(summary = "核销用户卡券")
    public CommonResult<Boolean> createCustomerCoupon(@Valid @RequestBody CustomerCouponSaveReqVO saveReqVO) {
        customerCouponService.couponVerification(saveReqVO);
        return success(true);
    }


    /**
     * 删除用户卡券
     *
     * @param id 用户卡券id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 23:01 2024/9/20
     **/
    @DeleteMapping("/delete")
    @Operation(summary = "删除用户卡券")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteCustomerCoupon(@RequestParam("id") String id) {
        customerCouponService.deleteCustomerCoupon(id);
        return success(true);
    }

    /**
     * 获取卡券信息及当前消费记录
     *
     * @param id 用户卡券id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.module.custom.vo.CustomerCouponRespVO>
     * @author PQZ
     * @date 22:56 2024/9/20
     **/
    @GetMapping("/get")
    @Operation(summary = "获得用户卡券")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<CustomerCouponRespVO> getCustomerCoupon(@RequestParam("id") String id) {
        return success(customerCouponService.getCustomerCoupon(id));
    }


}