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

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 javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.newfeifan.mall.framework.common.pojo.PageParam;
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.framework.excel.core.util.ExcelUtils;

import cn.newfeifan.mall.framework.operatelog.core.annotations.OperateLog;
import static cn.newfeifan.mall.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.newfeifan.mall.module.distri.controller.app.applicationforwithdrawalchannel.vo.*;
import cn.newfeifan.mall.module.distri.dal.dataobject.applicationforwithdrawalchannel.ApplicationForWithdrawalChannelDO;
import cn.newfeifan.mall.module.distri.service.applicationforwithdrawalchannel.ApplicationForWithdrawalChannelService;

@Tag(name = "用户 APP - 提现渠道记录")
@RestController
@RequestMapping("/distri/application-for-withdrawal-channel")
@Validated
public class AppApplicationForWithdrawalChannelController {

    @Resource
    private ApplicationForWithdrawalChannelService applicationForWithdrawalChannelService;

    @PostMapping("/create")
    @Operation(summary = "创建提现渠道记录")
    public CommonResult<Long> createApplicationForWithdrawalChannel(@Valid @RequestBody AppApplicationForWithdrawalChannelSaveReqVO createReqVO) {
        return success(applicationForWithdrawalChannelService.createApplicationForWithdrawalChannel(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新提现渠道记录")
    public CommonResult<Boolean> updateApplicationForWithdrawalChannel(@Valid @RequestBody AppApplicationForWithdrawalChannelSaveReqVO updateReqVO) {
        applicationForWithdrawalChannelService.updateApplicationForWithdrawalChannel(updateReqVO);
        return success(true);
    }

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

    @GetMapping("/get")
    @Operation(summary = "获得提现渠道记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppApplicationForWithdrawalChannelRespVO> getApplicationForWithdrawalChannel(@RequestParam("id") Long id) {
        ApplicationForWithdrawalChannelDO applicationForWithdrawalChannel = applicationForWithdrawalChannelService.getApplicationForWithdrawalChannel(id);
        return success(BeanUtils.toBean(applicationForWithdrawalChannel, AppApplicationForWithdrawalChannelRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得提现渠道记录分页")
    public CommonResult<PageResult<AppApplicationForWithdrawalChannelRespVO>> getApplicationForWithdrawalChannelPage(@Valid AppApplicationForWithdrawalChannelPageReqVO pageReqVO) {
        PageResult<ApplicationForWithdrawalChannelDO> pageResult = applicationForWithdrawalChannelService.getApplicationForWithdrawalChannelPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppApplicationForWithdrawalChannelRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出提现渠道记录 Excel")
    @OperateLog(type = EXPORT)
    public void exportApplicationForWithdrawalChannelExcel(@Valid AppApplicationForWithdrawalChannelPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ApplicationForWithdrawalChannelDO> list = applicationForWithdrawalChannelService.getApplicationForWithdrawalChannelPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "提现渠道记录.xls", "数据", AppApplicationForWithdrawalChannelRespVO.class,
                        BeanUtils.toBean(list, AppApplicationForWithdrawalChannelRespVO.class));
    }

}