package cn.newfeifan.mall.module.distri.controller.app.applicationforwithdrawal;

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.distri.controller.app.applicationforwithdrawal.vo.*;
import cn.newfeifan.mall.module.distri.dal.dataobject.applicationforwithdrawal.ApplicationForWithdrawalDO;
import cn.newfeifan.mall.module.distri.service.applicationforwithdrawal.ApplicationForWithdrawalService;

@Tag(name = "用户 APP - 提现申请记录")
@RestController
@RequestMapping("/distri/application-for-withdrawal")
@Validated
public class AppApplicationForWithdrawalController {

    @Resource
    private ApplicationForWithdrawalService applicationForWithdrawalService;

    @PostMapping("/create")
    @Operation(summary = "创建提现申请记录")
    public CommonResult<Long> createApplicationForWithdrawal(@Valid @RequestBody AppApplicationForWithdrawalSaveReqVO createReqVO) {
        return success(applicationForWithdrawalService.createApplicationForWithdrawal(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新提现申请记录")
    public CommonResult<Boolean> updateApplicationForWithdrawal(@Valid @RequestBody AppApplicationForWithdrawalSaveReqVO updateReqVO) {
        applicationForWithdrawalService.updateApplicationForWithdrawal(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除提现申请记录")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteApplicationForWithdrawal(@RequestParam("id") Long id) {
        applicationForWithdrawalService.deleteApplicationForWithdrawal(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得提现申请记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppApplicationForWithdrawalRespVO> getApplicationForWithdrawal(@RequestParam("id") Long id) {
        ApplicationForWithdrawalDO applicationForWithdrawal = applicationForWithdrawalService.getApplicationForWithdrawal(id);
        return success(BeanUtils.toBean(applicationForWithdrawal, AppApplicationForWithdrawalRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得提现申请记录分页")
    public CommonResult<PageResult<AppApplicationForWithdrawalRespVO>> getApplicationForWithdrawalPage(@Valid AppApplicationForWithdrawalPageReqVO pageReqVO) {
        PageResult<ApplicationForWithdrawalDO> pageResult = applicationForWithdrawalService.getApplicationForWithdrawalPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppApplicationForWithdrawalRespVO.class));
    }

}