package cn.newfeifan.mall.module.distri.controller.admin.consumptiontopuplog;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.newfeifan.mall.framework.common.pojo.PageResult;
import cn.newfeifan.mall.framework.common.pojo.CommonResult;
import cn.newfeifan.mall.framework.common.util.object.BeanUtils;

import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;


import cn.newfeifan.mall.module.distri.controller.admin.consumptiontopuplog.vo.*;
import cn.newfeifan.mall.module.distri.dal.dataobject.consumptiontopuplog.ConsumptionTopUpLogDO;
import cn.newfeifan.mall.module.distri.service.consumptiontopuplog.ConsumptionTopUpLogService;

@Tag(name = "管理后台 - 平台消费分充值记录")
@RestController
@RequestMapping("/distri/consumption-top-up-log")
@Validated
public class ConsumptionTopUpLogController {

    @Resource
    private ConsumptionTopUpLogService consumptionTopUpLogService;

    @PostMapping("/create")
    @Operation(summary = "创建平台消费分充值记录")
    @PreAuthorize("@ss.hasPermission('distri:consumption-top-up-log:create')")
    public CommonResult<Long> createConsumptionTopUpLog(@Valid @RequestBody ConsumptionTopUpLogSaveReqVO createReqVO) {
        return success(consumptionTopUpLogService.createConsumptionTopUpLog(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新平台消费分充值记录")
    @PreAuthorize("@ss.hasPermission('distri:consumption-top-up-log:update')")
    public CommonResult<Boolean> updateConsumptionTopUpLog(@Valid @RequestBody ConsumptionTopUpLogSaveReqVO updateReqVO) {
        consumptionTopUpLogService.updateConsumptionTopUpLog(updateReqVO);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得平台消费分充值记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('distri:consumption-top-up-log:query')")
    public CommonResult<ConsumptionTopUpLogRespVO> getConsumptionTopUpLog(@RequestParam("id") Long id) {
        ConsumptionTopUpLogDO consumptionTopUpLog = consumptionTopUpLogService.getConsumptionTopUpLog(id);
        return success(BeanUtils.toBean(consumptionTopUpLog, ConsumptionTopUpLogRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得平台消费分充值记录分页")
    @PreAuthorize("@ss.hasPermission('distri:consumption-top-up-log:query')")
    public CommonResult<PageResult<ConsumptionTopUpLogRespVO>> getConsumptionTopUpLogPage(@Valid ConsumptionTopUpLogPageReqVO pageReqVO) {
        PageResult<ConsumptionTopUpLogDO> pageResult = consumptionTopUpLogService.getConsumptionTopUpLogPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ConsumptionTopUpLogRespVO.class));
    }

    @GetMapping("/isFirstConsumption")
    @Operation(summary = "是否是第一次充值消费分")
    @PreAuthorize("@ss.hasPermission('distri:consumption-top-up-log:query')")
    public CommonResult<ConsumptionInfoVO> isFirstConsumption(@RequestParam("userId") Long userId) {
        return success(consumptionTopUpLogService.isFirstConsumption(userId));
    }

    @GetMapping("/ptTopUpWithUserTopUpList")
    @Operation(summary = "获取平台充值和用户充值记录")
    @PreAuthorize("@ss.hasPermission('distri:consumption-top-up-log:ptTopUpWithUserTopUpList')")
    public CommonResult<PtTopUpWithUserTopUpRespVO> ptTopUpWithUserTopUpList() {
        return success(consumptionTopUpLogService.ptTopUpWithUserTopUpList());
    }
}