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

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.member.entity.MemberCoupon;
import cn.iocoder.yudao.module.member.service.MemberCouponService;
import cn.iocoder.yudao.module.member.vo.MemberCouponPageReqVO;
import cn.iocoder.yudao.module.member.vo.MemberCouponRespVO;
import cn.iocoder.yudao.module.member.vo.MemberCouponSaveReqVO;
import cn.iocoder.yudao.module.member.vo.MemberLevelRespVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 基础卡券")
@RestController
@RequestMapping("/member/coupon")
@Validated
public class MemberCouponController {

    @Resource
    private MemberCouponService couponService;

    /**
     * 创建基础卡券
     *
     * @param createReqVO MemberCouponSaveReqVO
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.String>
     * @author PQZ
     * @date 14:19 2024/9/19
     **/
    @PostMapping("/create")
    @Operation(summary = "创建基础卡券")
    @PreAuthorize("@ss.hasPermission('member:coupon:create')")
    public CommonResult<Boolean> createCoupon(@Valid @RequestBody MemberCouponSaveReqVO saveReqVO) {
        couponService.saveCoupon(saveReqVO);
        return success(true);
    }

    /**
     * 更新基础卡券
     *
     * @param updateReqVO MemberCouponSaveReqVO
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 14:19 2024/9/19
     **/
    @PutMapping("/update")
    @Operation(summary = "更新基础卡券")
    @PreAuthorize("@ss.hasPermission('member:coupon:update')")
    public CommonResult<Boolean> updateCoupon(@Valid @RequestBody MemberCouponSaveReqVO saveReqVO) {
        couponService.saveCoupon(saveReqVO);
        return success(true);
    }

    /**
     * 复制附属权益
     *
     * @param saveReqVO MemberCouponSaveReqVO实体
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 21:34 2024/9/19
     **/
    @PostMapping("/copy")
    @Operation(summary = "复制附属权益")
    @PreAuthorize("@ss.hasPermission('member:coupon:update')")
    public CommonResult<Boolean> copyCoupon(@Valid @RequestBody MemberCouponSaveReqVO saveReqVO) {
        couponService.copyMemberCoupon(saveReqVO);
        return success(true);
    }

    /**
     * 删除基础卡券
     *
     * @param id 基础卡券id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 14:19 2024/9/19
     **/
    @DeleteMapping("/delete")
    @Operation(summary = "删除基础卡券")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('member:coupon:delete')")
    public CommonResult<Boolean> deleteCoupon(@RequestParam("id") String id) {
        couponService.deleteCoupon(id);
        return success(true);
    }

    /**
     * 通过id获取基础卡券
     *
     * @param id 卡券id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.module.member.vo.MemberCouponRespVO>
     * @author PQZ
     * @date 14:20 2024/9/19
     **/
    @GetMapping("/get")
    @Operation(summary = "获得基础卡券")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('member:coupon:query')")
    public CommonResult<MemberCouponRespVO> getCoupon(@RequestParam("id") String id) {
        return success(couponService.getCoupon(id));
    }

    /**
     * 分页查询基础卡券信息
     *
     * @param pageReqVO MemberCouponPageReqVO实体
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.framework.common.pojo.PageResult < cn.iocoder.yudao.module.member.vo.MemberCouponRespVO>>
     * @author PQZ
     * @date 14:20 2024/9/19
     **/
    @GetMapping("/page")
    @Operation(summary = "获得基础卡券分页")
    @PreAuthorize("@ss.hasPermission('member:coupon:query')")
    public CommonResult<IPage<?>> getCouponPage(@Valid MemberCouponPageReqVO pageReqVO,
                                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<MemberCouponRespVO> page = new Page<>(pageNo, pageSize);
        return success(couponService.queryListPage(pageReqVO, page));
    }


}