package com.sckw.payment.controller;

import com.sckw.core.web.response.HttpResult;
import com.sckw.payment.model.dto.Id;
import com.sckw.payment.model.vo.req.*;
import com.sckw.payment.model.vo.req.page.MoneyPage;
import com.sckw.payment.model.vo.req.page.PrePayPage;
import com.sckw.payment.model.vo.req.page.RefundPage;
import com.sckw.payment.service.WalletService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 钱包
 *
 * @author xucaiqin
 * @date 2023-08-28 15:36:48
 */
@Validated
@RestController
@RequestMapping("/wallet")
@Slf4j
public class WalletController {
    @Resource
    private WalletService walletService;

    /**
     * 开户
     *
     * @return
     */
    @PostMapping("createUser")
    public HttpResult createUser(@RequestBody @Valid CreateUserReq createUserReq) {
        return HttpResult.ok(walletService.createUser(createUserReq));
    }

    /**
     * 渠道用户开通信息
     *
     * @param uid
     * @param channel
     * @return
     */
    @GetMapping("userInfo")
    public HttpResult userInfo(@NotBlank(message = "uid不能为空") @RequestParam("uid") String uid,
                               @NotBlank(message = "channel不能为空") @RequestParam("channel") String channel) {
        return HttpResult.ok(walletService.userInfo(uid, channel));
    }

    /**
     * 钱包总览信息
     *
     * @return
     */
    @GetMapping("overview")
    public HttpResult overview(boolean queryChannel) {
        return HttpResult.ok(walletService.walletOverview(queryChannel));
    }

    /**
     * 渠道开通情况
     *
     * @return
     */
    @GetMapping("channel")
    public HttpResult channel() {
        return HttpResult.ok(walletService.channel());
    }

    /**
     * 查询资金明细
     *
     * @return
     */
    @GetMapping("detail")
    public HttpResult detail(WalletDetailReq walletDetailReq) {
        return HttpResult.ok(walletService.walletDetail(walletDetailReq));
    }

    /**
     * 查询资金明细-按渠道统计数量
     *
     * @return
     */
    @GetMapping("detailCount")
    public HttpResult count(String entName) {
        return HttpResult.ok(walletService.walletCount(entName));
    }

    /**
     * 新增账目
     *
     * @param addWalletReq
     * @return
     */
    @PostMapping("add")
    public HttpResult add(@RequestBody @Valid AddWalletReq addWalletReq) {
        return HttpResult.ok(walletService.addWallet(addWalletReq));
    }

    /**
     * 账目充值
     *
     * @param addWalletReq
     * @return
     */
    @PostMapping("recharge")
    public HttpResult recharge(@RequestBody @Valid WalletAppendReq addWalletReq) {
        return HttpResult.ok(walletService.addWalletMoney(addWalletReq));
    }

    /**
     * 提现
     *
     * @param cashWalletReq
     * @return
     */
    @PostMapping("cashOUt")
    public HttpResult cashOUt(@RequestBody @Valid CashWalletReq cashWalletReq) {
        return HttpResult.ok(walletService.cashOUt(cashWalletReq));
    }

    /**
     * 重新提现
     *
     * @param cashWalletReq
     * @return
     */
    @PostMapping("reCashOUt")
    public HttpResult reCashOUt(@RequestBody @Valid CashWalletReq cashWalletReq) {
        return HttpResult.ok(walletService.reCashOUt(cashWalletReq));
    }

    /**
     * 转账
     *
     * @param transferReq
     * @return
     */
    @PostMapping("transfer")
    public HttpResult transfer(@RequestBody @Valid TransferReq transferReq) {
        return HttpResult.ok(walletService.transfer(transferReq));
    }

    /**
     * 提现记录
     *
     * @param cashPageReq
     * @return
     */
    @GetMapping("cashList")
    public HttpResult cashList(CashPageReq cashPageReq) {
        return HttpResult.ok(walletService.cashList(cashPageReq));
    }

    /**
     * 提现记录 分类统计
     *
     * @param cashPageReq
     * @return
     */
    @GetMapping("cashCount")
    public HttpResult cashCount(CashPageReq cashPageReq) {
        return HttpResult.ok(walletService.cashCount(cashPageReq));
    }

    /**
     * 预付列表
     *
     * @param prePayPage
     * @return
     */
    @GetMapping("prePayList")
    public HttpResult prePayList(PrePayPage prePayPage) {
        return HttpResult.ok(walletService.prePayList(prePayPage));
    }

    /**
     * 预付列表-按渠道统计数量
     *
     * @return
     */
    @GetMapping("prePayCount")
    public HttpResult prePayCount(String entName) {
        return HttpResult.ok(walletService.prePayCount(entName));
    }

    /**
     * 预收列表
     *
     * @param prePayPage
     * @return
     */
    @GetMapping("preReceiveList")
    public HttpResult preReceiveList(PrePayPage prePayPage) {
        return HttpResult.ok(walletService.preReceiveList(prePayPage));
    }

    /**
     * 预收列表-按渠道统计数量
     *
     * @return
     */
    @GetMapping("preReceiveCount")
    public HttpResult preReceiveCount(String entName) {
        return HttpResult.ok(walletService.preReceiveCount(entName));
    }

    /**
     * 预付校验
     *
     * @param prePayCheck
     * @return
     */
    @PostMapping("prePayCheck")
    public HttpResult prePayCheck(@RequestBody @Valid PrePayCheck prePayCheck) {
        return HttpResult.ok(walletService.prePayCheck(prePayCheck));
    }

    /**
     * 新增预付
     *
     * @param prePay
     * @return
     */
    @PostMapping("addPrePay")
    public HttpResult addPrePay(@RequestBody @Valid PrePay prePay) {
        return HttpResult.ok(walletService.addPrePay(prePay));
    }

    /**
     * 预付追加校验
     *
     * @param appendPayCheck
     * @return
     */
    @PostMapping("appendCheck")
    public HttpResult prePayAppendCheck(@RequestBody @Valid AppendPayCheck appendPayCheck) {
        return HttpResult.ok(walletService.appendCheck(appendPayCheck));
    }

    /**
     * 预付追加
     *
     * @param prePay
     * @return
     */
    @PostMapping("prePayAppend")
    public HttpResult prePayAppend(@RequestBody @Valid PrePayAppend prePay) {
        return HttpResult.ok(walletService.prePayAppend(prePay));
    }


    /*退款*/

    /**
     * 申请退款(预付方)
     *
     * @param refundReq
     * @return
     */
    @PostMapping("applyRefund")
    public HttpResult applyRefund(@RequestBody @Valid ApplyRefundReq refundReq) {
        return HttpResult.ok(walletService.applyRefund(refundReq));
    }


    /**
     * 查询退款列表(预收方)
     *
     * @param refundPage
     * @return
     */
    @PostMapping("refundList")
    public HttpResult refundList(@RequestBody @Valid RefundPage refundPage) {
        return HttpResult.ok(walletService.refundList(refundPage));
    }


    /**
     * 发起退款（预收方）余额查询及校验
     *
     * @param id 退款单id
     * @return
     */
    @PostMapping("refundCheck")
    public HttpResult refundCheck(@RequestBody @Valid Id id) {
        return HttpResult.ok(walletService.refundCheck(id.getIdLong()));
    }

    /**
     * 确认退款
     *
     * @param refundReq
     * @return
     */
    @PostMapping("refund")
    public HttpResult refund(@RequestBody @Valid RefundReq refundReq) {
        return HttpResult.ok(walletService.launchRefund(refundReq));
    }

    /**
     * 驳回退款
     *
     * @param refundReq
     * @return
     */
    @PostMapping("backRefund")
    public HttpResult back(@RequestBody @Valid RefundBackReq refundReq) {
        return HttpResult.ok(walletService.backRefund(refundReq));
    }



    /*资金明细-详细记录*/

    /**
     * 充值订单
     *
     * @param moneyPage
     * @return
     */
    @PostMapping("rechargeOrder")
    public HttpResult rechargeList(@RequestBody @Valid MoneyPage moneyPage) {
        return HttpResult.ok(walletService.rechargeList(moneyPage));
    }

    /**
     * 转账订单
     *
     * @param moneyPage
     * @return
     */
    @PostMapping("transferOrder")
    public HttpResult transferList(@RequestBody @Valid MoneyPage moneyPage) {
        return HttpResult.ok(walletService.transferOrder(moneyPage));
    }

    /**
     * 退款订单
     *
     * @param moneyPage
     * @return
     */
    @PostMapping("refundOrder")
    public HttpResult refundOrder(@RequestBody @Valid MoneyPage moneyPage) {
        return HttpResult.ok(walletService.refundOrder(moneyPage));
    }

    /**
     * 提现订单
     *
     * @param moneyPage
     * @return
     */
    @PostMapping("cashOrder")
    public HttpResult cashOrder(@RequestBody @Valid MoneyPage moneyPage) {
        return HttpResult.ok(walletService.cashOrder(moneyPage));
    }

    /*提现-详细记录*/

    /**
     * 提现
     *
     * @param cashDetailReq
     * @return
     */
    @PostMapping("cashDetail")
    public HttpResult cashDetail(@RequestBody @Valid CashDetailReq cashDetailReq) {
        return HttpResult.ok(walletService.cashDetail(cashDetailReq));
    }
    /*预付-详细记录*/

    /**
     * 预付订单
     *
     * @param moneyPage
     * @return
     */
    @PostMapping("prePayOrder")
    public HttpResult prePayOrder(@RequestBody @Valid MoneyPage moneyPage) {
        return HttpResult.ok(walletService.prePayOrder(moneyPage));
    }

    /**
     * 退款记录
     *
     * @param moneyPage
     * @return
     */
    @PostMapping("prePayRefund")
    public HttpResult prePayRefund(@RequestBody @Valid MoneyPage moneyPage) {
        return HttpResult.ok(walletService.prePayRefund(moneyPage));
    }
    /*预收-详细记录*/

    /**
     * 预收订单
     *
     * @param moneyPage
     * @return
     */
    @PostMapping("preReceiveOrder")
    public HttpResult preReceiveOrder(@RequestBody @Valid MoneyPage moneyPage) {
        return HttpResult.ok(walletService.preReceiveOrder(moneyPage));
    }

    /**
     * 退款订单
     *
     * @param moneyPage
     * @return
     */
    @PostMapping("preReceiveRefund")
    public HttpResult preReceiveRefund(@RequestBody @Valid MoneyPage moneyPage) {
        return HttpResult.ok(walletService.preReceiveRefund(moneyPage));
    }
}
