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.CustomerActive;
import cn.iocoder.yudao.module.custom.service.CustomerActiveService;
import cn.iocoder.yudao.module.custom.vo.CustomerActivePageReqVO;
import cn.iocoder.yudao.module.custom.vo.CustomerActiveRespVO;
import cn.iocoder.yudao.module.custom.vo.CustomerActiveSaveReqVO;
import cn.iocoder.yudao.module.member.vo.ActiveMainPageReqVO;
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 java.util.List;

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

@Tag(name = "管理后台 - 用户参与活动记录")
@RestController
@RequestMapping("/base/customer-active")
@Validated
public class CustomerActiveController {

    @Resource
    private CustomerActiveService customerActiveService;

    /**
     * 参加活动
     *
     * @param createReqVO CustomerActiveSaveReqVO
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.String>
     * @author PQZ
     * @date 9:49 2024/9/21
     **/
    @PostMapping("/attendActive")
    @Operation(summary = "参加活动")
    public CommonResult<Boolean> attendActive(@RequestBody CustomerActiveSaveReqVO createReqVO) {
        customerActiveService.attendActiveOrder(createReqVO);
        return success(true);
    }

    /**
     * 新版参加活动
     *
     * @param createReqVO CustomerActiveSaveReqVO
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.String>
     * @author PQZ
     * @date 9:49 2024/9/21
     **/
    @PostMapping("/attendActiveOrder")
    @Operation(summary = "参加活动")
    public CommonResult<Boolean> attendActiveOrder(@RequestBody CustomerActiveSaveReqVO createReqVO) {
        customerActiveService.attendActiveOrder(createReqVO);
        return success(true);
    }

    /**
     * 充值
     *
     * @param createReqVO CustomerActiveSaveReqVO实体
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 16:34 2024/9/28
     **/
    @PostMapping("/recharge")
    @Operation(summary = "充值")
    public CommonResult<Boolean> recharge(@RequestBody CustomerActiveSaveReqVO createReqVO) {
        customerActiveService.recharge(createReqVO);
        return success(true);
    }


    @DeleteMapping("/delete")
    @Operation(summary = "删除用户参与活动记录")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteCustomerActive(@RequestParam("id") String id) {
        customerActiveService.deleteCustomerActive(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得用户参与活动记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<CustomerActiveRespVO> getCustomerActive(@RequestParam("id") String id) {
        CustomerActive customerActive = customerActiveService.getCustomerActive(id);
        return success(BeanUtils.toBean(customerActive, CustomerActiveRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得用户参与活动记录分页")
    public CommonResult<PageResult<CustomerActiveRespVO>> getCustomerActivePage(@Valid CustomerActivePageReqVO pageReqVO) {
        PageResult<CustomerActive> pageResult = customerActiveService.getCustomerActivePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CustomerActiveRespVO.class));
    }


    /**
     * @param pageReqVO ActiveMainPageReqVO实体
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<com.baomidou.mybatisplus.core.metadata.IPage < ?>>
     * @author PQZ
     * @date 16:12 2024/9/23
     **/
    @GetMapping("/list")
    @Operation(summary = "可参与营销活动")
    public CommonResult<List<?>> getActiveMainPage(ActiveMainPageReqVO pageReqVO) {
        return success(customerActiveService.isJoinActive(pageReqVO));
    }


}