package com.sckw.payment.controller;


import com.sckw.core.web.response.BaseResult;
import com.sckw.core.web.response.result.PageDataResult;
import com.sckw.excel.utils.ExcelUtil;
import com.sckw.payment.repose.KwpBizWalletPageResponse;
import com.sckw.payment.repose.KwpBizWalletPrepayPageResponse;
import com.sckw.payment.repose.vo.KwpBizWalletPrepayExcelVO;
import com.sckw.payment.request.KwpBizWalletPrepayQueryRequest;
import com.sckw.payment.request.KwpBizWalletPrepayRequest;
import com.sckw.payment.request.KwpBizWalletQueryRequest;
import com.sckw.payment.request.KwpBizWalletSaveRequest;
import com.sckw.payment.service.wallet.KwpBizWalletService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Author: donglang
 * Time: 2025-11-03
 * Des: 钱包管理Controller
 * Version: 1.0
 */
@Tag(name = "线下钱包管理", description = "提供钱包相关操作接口")
@RestController
@RequestMapping("/biz/wallet")
@RequiredArgsConstructor
public class KwpBizWalletController {

    private final KwpBizWalletService kwpBizWalletService;


    /**
     * 分页查询钱包明细
     *
     * @param request 查询参数
     * @return 钱包分页列表
     */
    @Operation(summary = "分页查询钱包明细", description = "根据条件分页查询钱包明细信息")
    @PostMapping("/pageBizWalletList")
    public BaseResult<PageDataResult<KwpBizWalletPageResponse>> pageBizWalletList(@RequestBody KwpBizWalletQueryRequest request) {
        PageDataResult<KwpBizWalletPageResponse> WalletPageList = kwpBizWalletService.pageBizWalletList(request);
        return BaseResult.success(WalletPageList);
    }

    /**
     * 新增钱包
     *
     * @param request 钱包信息
     * @return 操作结果
     */
    @Operation(summary = "新增钱包", description = "新增一个钱包账户")
    @PostMapping("/addWallet")
    public BaseResult addWallet(@RequestBody @Validated KwpBizWalletSaveRequest request) {
        kwpBizWalletService.addWallet(request);
        return BaseResult.success();
    }

    /**
     * 钱包状态更新
     *
     * @param id 钱包ID
     * @return 操作结果
     */
    @Operation(summary = "更新钱包状态", description = "根据ID更新钱包状态")
    @Parameter(name = "id", description = "钱包ID", required = true)
    @PostMapping("/updateWallet")
    public BaseResult updateWallet(Long id) {
        kwpBizWalletService.updateWallet(id);
        return BaseResult.success();
    }

    /**
     * 钱包金额更新
     *
     * @param request 钱包金额更新信息
     * @return 操作结果
     */
    @Operation(summary = "更新钱包金额", description = "更新钱包金额信息")
    @PostMapping("/updateWalletAmount")
    public BaseResult updateWalletAmount(@RequestBody @Validated KwpBizWalletPrepayRequest request) {
        kwpBizWalletService.updateWalletAmount(request);
        return BaseResult.success();
    }

    /**
     * 分页查询钱包冻账明细
     *
     * @param request 查询参数
     * @return 冻结明细分页列表
     */
    @Operation(summary = "分页查询钱包冻账明细", description = "根据条件分页查询钱包冻结明细信息")
    @PostMapping("/walletPrepayDetail")
    public BaseResult<PageDataResult<KwpBizWalletPrepayPageResponse>> walletPrepayDetail(@RequestBody @Validated KwpBizWalletPrepayQueryRequest request) {
        PageDataResult<KwpBizWalletPrepayPageResponse> walletPrepayPageDataResult = kwpBizWalletService.walletPrepayDetail(request);
        return BaseResult.success(walletPrepayPageDataResult);
    }

    /**
     * 钱包冻账明细导出
     *
     * @param response HTTP响应
     * @param request  查询参数
     * @return 操作结果
     */
    @Operation(summary = "导出钱包冻结明细", description = "导出钱包冻结明细为Excel文件")
    @PostMapping("/exportWalletPrepay")
    public void exportWalletPrepay(@RequestBody @Validated KwpBizWalletPrepayQueryRequest request, HttpServletResponse response) {
        //查询导出数据
        List<KwpBizWalletPrepayExcelVO> excelVOList = kwpBizWalletService.queryExportWalletPrepay(request);
        //导出
        ExcelUtil.downData(response, KwpBizWalletPrepayExcelVO.class, excelVOList);
    }


}
