package com.cool.store.controller.webc;

import com.cool.store.dto.wallet.*;
import com.cool.store.request.wallet.*;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.wallet.WalletService;
import com.cool.store.vo.wallet.*;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * <p>
 * Mini钱包 前端控制器
 * </p>
 *
 * @author wangff
 * @since 2025/11/14
 */
@Api(tags = "Mini钱包")
@RestController
@RequestMapping("/mini/wallet")
@RequiredArgsConstructor
@Validated
public class MiniWalletController {
    private final WalletService walletService;

    @ApiOperation("步骤1：平安银行钱包账号创建")
    @PostMapping("/accountCreate")
    public ResponseResult<Boolean> accountCreate(@RequestBody @Validated AccountCreateRequest request) {
        return ResponseResult.success(walletService.accountCreate(request));
    }

    @ApiOperation("步骤2：鉴权申请")
    @PostMapping("/authentication")
    public ResponseResult<AccountAuthenticationVO> authentication(@RequestBody @Validated WalletShopRequest request) {
        return ResponseResult.success(walletService.authentication(request));
    }

    @ApiOperation("步骤3：账号开通（步骤2接口返回4时无需调用）")
    @PostMapping("/openAccount")
    public ResponseResult<Boolean> openAccount(@RequestBody @Validated AccountOpenRequest request) {
        return ResponseResult.success(walletService.openAccount(request));
    }

    @ApiOperation("支行信息查询")
    @PostMapping("/bankList")
    public ResponseResult<PageInfo<BankVO>> getBankList(@RequestBody BankListRequest request) {
        return ResponseResult.success(walletService.getBankList(request));
    }

    @ApiOperation("账户列表")
    @GetMapping("/accountList")
    public ResponseResult<AccountDataVO> getAccountList(AccountQueryRequest request) {
        return ResponseResult.success(walletService.getAccountList(request));
    }

    @ApiOperation("账户详情")
    @PostMapping("/accountInfo")
    public ResponseResult<AccountInfoVO> getAccountInfo(@RequestBody AccountQueryRequest request) {
        return ResponseResult.success(walletService.getAccountInfo(request));
    }

    @ApiOperation("账户流水")
    @PostMapping("/billPage")
    public ResponseResult<AccountBillPageVO> getBillPage(@RequestBody @Validated AccountBillQueryRequest request) {
        return ResponseResult.success(walletService.getBillPage(request));
    }

    @ApiOperation("交易流水详情")
    @GetMapping("/billDetail")
    public ResponseResult<TradeRecordDTO> getBillDetail(BillDetailRequest request) {
        return ResponseResult.success(walletService.getBillDetail(request));
    }

    @ApiOperation("密码维护")
    @PostMapping("/passwordUpdate")
    public ResponseResult<Boolean> passwordUpdate(@RequestBody @Validated AccountPasswordRequest request) {
        return ResponseResult.success(walletService.passwordUpdate(request));
    }

    @ApiOperation("门店是否存在密码")
    @PostMapping("/existPwd")
    public ResponseResult<PasswordDTO> passwordUpdate(@RequestBody @Validated OutStoreIdRequest request) {
        return ResponseResult.success(walletService.existPassword(request));
    }



    @ApiOperation("账户充值")
    @PostMapping("/payment")
    public ResponseResult<AccountPaymentVO> payment(@RequestBody @Validated AccountPaymentRequest request) {
        return ResponseResult.success(walletService.payment(request));
    }

    @ApiOperation("未支付充值订单分页查询")
    @GetMapping("/nonPaymentPage")
    public ResponseResult<PageInfo<WalletPaymentOrderVO>> nonPaymentPage(LargePaymentQueryRequest request) {
        return ResponseResult.success(walletService.nonPaymentOrderPage(request));
    }

    @ApiOperation("根据预支付id查询收款账户详情")
    @GetMapping("/paymentDetail")
    public ResponseResult<AccountPaymentVO> paymentDetail(@NotBlank(message = "预支付id不能为空") String paymentId) {
        return ResponseResult.success(walletService.paymentDetail(paymentId));
    }

    @ApiOperation("提现")
    @PostMapping("/withDrawer")
    public ResponseResult<WithDrawerDTO> withDrawer(@RequestBody @Validated WalletWithDrawerRequest request) {
        return ResponseResult.success(walletService.withDrawer(request));
    }
    @ApiOperation("根据门店编码查询开通基础信息")
    @GetMapping("/getOpenBasicInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeId", value = "门店id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "storeCode", value = "门店编号", required = true, dataType = "String"),
    })
    public ResponseResult<OpenBasicInfoDTO> getOpenBasicInfo(@NotBlank(message = "门店id不能为空") String storeId,
                                                             @NotBlank(message = "门店编码不能为空") String storeCode) {
        return ResponseResult.success(walletService.getOpenBasicInfo(storeId, storeCode));
    }

    @ApiOperation("提交开通")
    @PostMapping("/openOnlineBankAccount")
    public ResponseResult<Boolean> openOnlineBankAccount(@RequestBody @Validated CoolOpenBasicInfoRequest request) {
        return ResponseResult.success(walletService.openOnlineBankAccount(request));
    }

    @ApiOperation("新店网商钱包提交开通")
    @PostMapping("/newOpenOnlineBankAccount")
    public ResponseResult<Boolean> newStoreOpenOnlineBankAccount(@RequestBody @Validated NewWsCreateAccountRequest request) {
        return ResponseResult.success(walletService.newStoreOpenOnlineBankAccount(request));
    }

    @ApiOperation("网商账户激活")
    @PostMapping("/onlineBankActive")
    public ResponseResult<Boolean> onlineBankActive(@RequestBody @Validated StoreShopRequest request) {
        return ResponseResult.success(walletService.onlineBankActive(request));
    }

    @ApiOperation("银行列表")
    @GetMapping("/findBankHeadName")
    public ResponseResult<List<BankInfoDTO>> findBankHeadName() {
        return ResponseResult.success(walletService.findBankHeadName());
    }

    @ApiOperation("网商充值账户查询")
    @PostMapping("/wsPayAccountQuery")
    public ResponseResult<WsPayAccountDTO> wsPayAccountQuery(@RequestBody @Validated StoreShopRequest request) {
        return ResponseResult.success(walletService.wsPayAccountQuery(request));
    }
}
