package cn.newfeifan.mall.module.trade.controller.app.ptsettlement;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

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.trade.controller.app.ptsettlement.vo.*;
import cn.newfeifan.mall.module.trade.dal.dataobject.ptsettlement.PtSettlementDO;
import cn.newfeifan.mall.module.trade.service.ptsettlement.PtSettlementService;

@Tag(name = "用户 APP - 平台每日结算信息表，记录店铺的结算信息")
@RestController
@RequestMapping("/trade/pt-settlement")
@Validated
public class AppPtSettlementController {

    @Resource
    private PtSettlementService ptSettlementService;

    @PostMapping("/create")
    @Operation(summary = "创建平台每日结算信息表，记录店铺的结算信息")
    public CommonResult<Long> createPtSettlement(@Valid @RequestBody AppPtSettlementSaveReqVO createReqVO) {
        return success(ptSettlementService.createPtSettlement(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新平台每日结算信息表，记录店铺的结算信息")
    public CommonResult<Boolean> updatePtSettlement(@Valid @RequestBody AppPtSettlementSaveReqVO updateReqVO) {
        ptSettlementService.updatePtSettlement(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除平台每日结算信息表，记录店铺的结算信息")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deletePtSettlement(@RequestParam("id") Long id) {
        ptSettlementService.deletePtSettlement(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得平台每日结算信息表，记录店铺的结算信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppPtSettlementRespVO> getPtSettlement(@RequestParam("id") Long id) {
        PtSettlementDO ptSettlement = ptSettlementService.getPtSettlement(id);
        return success(BeanUtils.toBean(ptSettlement, AppPtSettlementRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得平台每日结算信息表，记录店铺的结算信息分页")
    public CommonResult<PageResult<AppPtSettlementRespVO>> getPtSettlementPage(@Valid AppPtSettlementPageReqVO pageReqVO) {
        PageResult<PtSettlementDO> pageResult = ptSettlementService.getPtSettlementPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppPtSettlementRespVO.class));
    }

}