package com.cf.imes.module.system.controller.admin.funds.recharge;

import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargePageReqVO;
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeRespVO;
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeSaveReqVO;
import com.cf.imes.module.system.dal.dataobject.funds.recharge.GiftMoneyDetailsDO;
import com.cf.imes.module.system.service.funds.recharge.RechargeActiveService;
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 jakarta.annotation.Resource;
import jakarta.validation.Valid;

import static com.cf.imes.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 充值活动管理")
@RestController
@RequestMapping("/system/recharge-active")
@Validated
public class RechargeActiveController {

    @Resource
    private RechargeActiveService productsService;

    @PutMapping("")
    @Operation(summary = "新建充值活动")
    @PreAuthorize("@ss.hasPermission('base:recharge-active:create')")
    public CommonResult<Long> createRechargeActive(@Valid @RequestBody RechargeSaveReqVO createReqVO) {
        return success(productsService.create(createReqVO));
    }

    @PostMapping("")
    @Operation(summary = "更新充值活动")
    @PreAuthorize("@ss.hasPermission('base:recharge-active:update')")
    public CommonResult<Boolean> updateRechargeActive(@Valid @RequestBody RechargeSaveReqVO updateReqVO) {
        productsService.update(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除充值活动")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('base:recharge-active:delete')")
    public CommonResult<Boolean> deleteRechargeActive(@PathVariable("id") Long id) {
        productsService.delete(id);
        return success(true);
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取充值活动")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('base:recharge-active:query')")
    public CommonResult<RechargeRespVO> getRechargeActive(@PathVariable("id") Long id) {
        GiftMoneyDetailsDO giftMoneyDetailsDO = productsService.get(id);
        return success(BeanUtils.toBean(giftMoneyDetailsDO, RechargeRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获取充值活动分页")
    @PreAuthorize("@ss.hasPermission('base:recharge-active:query')")
    public CommonResult<PageResult<RechargeRespVO>> getRechargeActivePage(@Valid RechargePageReqVO pageReqVO) {
        PageResult<GiftMoneyDetailsDO> pageResult = productsService.getPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, RechargeRespVO.class));
    }


}
