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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.member.entity.ActiveMain;
import cn.iocoder.yudao.module.member.service.ActiveMainService;
import cn.iocoder.yudao.module.member.vo.ActiveMainPageReqVO;
import cn.iocoder.yudao.module.member.vo.ActiveMainRespVO;
import cn.iocoder.yudao.module.member.vo.ActiveMainSaveReqVO;
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.validation.Valid;

import java.util.List;

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

@Tag(name = "管理后台 - 营销活动")
@RestController
@RequestMapping("/member/active-main")
@Validated
public class ActiveMainController {

    @Resource
    private ActiveMainService activeMainService;

    /**
     * 创建营销活动
     *
     * @param createReqVO ActiveMainSaveReqVO实体
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.String>
     * @author PQZ
     * @date 14:12 2024/9/19
     **/
    @PostMapping("/create")
    @Operation(summary = "创建营销活动")
    public CommonResult<Boolean> createActiveMain(@Valid @RequestBody ActiveMainSaveReqVO createReqVO) {
        activeMainService.saveActiveMain(createReqVO);
        return success(true);
    }

    /**
     * 更新营销活动
     *
     * @param updateReqVO ActiveMainSaveReqVO实体
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 14:12 2024/9/19
     **/
    @PutMapping("/update")
    @Operation(summary = "更新营销活动")
    public CommonResult<Boolean> updateActiveMain(@Valid @RequestBody ActiveMainSaveReqVO updateReqVO) {
        activeMainService.saveActiveMain(updateReqVO);
        return success(true);
    }

    /**
     * 删除营销活动
     *
     * @param id 营销活动id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 14:12 2024/9/19
     **/
    @DeleteMapping("/delete")
    @Operation(summary = "删除营销活动")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteActiveMain(@RequestParam("id") String id) {
        activeMainService.deleteActiveMain(id);
        return success(true);
    }

    /**
     * 通过营销活动id获取营销活动
     *
     * @param id 营销活动id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.module.member.vo.ActiveMainRespVO>
     * @author PQZ
     * @date 14:13 2024/9/19
     **/
    @GetMapping("/get")
    @Operation(summary = "获得营销活动")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<ActiveMainRespVO> getActiveMain(@RequestParam("id") String id) {
        ActiveMainRespVO activeMain = activeMainService.getActiveMain(id,false);
        return success(activeMain);
    }

    /**
     * 分页查询营销活动
     *
     * @param pageReqVO ActiveMainPageReqVO
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.framework.common.pojo.PageResult < cn.iocoder.yudao.module.member.vo.ActiveMainRespVO>>
     * @author PQZ
     * @date 14:13 2024/9/19
     **/
    @GetMapping("/page")
    @Operation(summary = "获得营销活动分页")
    public CommonResult<IPage<?>> getActiveMainPage(ActiveMainPageReqVO pageReqVO,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<ActiveMainRespVO> page = new Page<>(pageNo, pageSize);
        return success(activeMainService.queryListPage(pageReqVO, page));
    }

}