package com.sckw.payment.controller;

import com.sckw.core.model.page.PageRes;
import com.sckw.core.web.response.HttpResult;
import com.sckw.payment.api.model.dto.common.R;
import com.sckw.payment.model.vo.req.CashVo;
import com.sckw.payment.model.vo.req.CashWalletReq;
import com.sckw.payment.model.vo.req.CreateUserReq;
import com.sckw.payment.model.vo.req.page.CashPage;
import com.sckw.payment.model.vo.req.page.ListPage;
import com.sckw.payment.model.vo.req.page.PayPage;
import com.sckw.payment.model.vo.req.page.PrePayPage;
import com.sckw.payment.model.vo.res.PrepayVo;
import com.sckw.payment.service.WalletService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
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
 */
@Tag(name = "钱包管理", description = "提供钱包相关操作接口")
@Validated
@RestController
@RequestMapping("/wallet")
@Slf4j
public class WalletController {
    @Resource
    private WalletService walletService;

    /**
     * 【接口】开户
     *
     * @param createUserReq 开户请求参数
     */
    @Operation(summary = "开户", description = "为用户开通钱包账户")
    @PostMapping("createUser")
    public HttpResult createUser(@RequestBody @Valid CreateUserReq createUserReq) {
        return HttpResult.ok(walletService.createUser(createUserReq));
    }

    /**
     * 【接口】钱包信息
     */
    @Operation(summary = "查询用户钱包信息", description = "查询用户钱包信息")
    @Parameter(name = "entId", description = "企业id", required = true)
    @GetMapping("/info")
    public R<Object> userInfo(@NotNull(message = "entId不能为空") @RequestParam("entId") Long entId) {
        return walletService.userInfo(entId);
    }

    /**
     * 【接口】可提现余额分页查询
     */
    @Operation(summary = "可提现余额分页查询", description = "可提现余额分页查询")
    @Parameter(name = "entId", description = "企业id", required = true)
    @PostMapping("/cashPage")
    public R<PageRes<CashVo>> cashPage(@RequestBody @Valid CashPage cashPage) {
        return R.ok(walletService.cashPage(cashPage));
    }

    /**
     * 【接口】提现
     *
     * @param cashWalletReq 提现参数
     * @return 操作结果
     */
    @Operation(summary = "提现", description = "发起提现操作")
    @PostMapping("cashOUt")
    public R<Object> cashOUt(@RequestBody @Valid CashWalletReq cashWalletReq) {
        return R.ok(walletService.cashOUt(cashWalletReq));
    }

    /*预付*/

    /**
     * 【接口】预付（待履约）清单分页查询
     *
     * @param listPage
     */
    @Operation(summary = "预付（待履约）清单分页查询", description = "预付（待履约）清单分页查询")
    @PostMapping("/prepayList")
    public R<Object> prepayList(@RequestBody @Valid ListPage listPage) {
        return R.ok(walletService.prepayList(listPage));
    }

    /**
     * 【接口】支付记录/预付记录
     */
    @Operation(summary = "支付记录/预付记录", description = "支付记录/预付记录")
    @PostMapping("/payList")
    public R<Object> prepayRecord(@RequestBody @Valid PayPage payPage) {
        return R.ok(walletService.prepayRecord(payPage));
    }

    /**
     * 【接口】预付（待履约）明细分页查询
     *
     * @param prePayPage 预付
     */
    @Operation(summary = "预付（待履约）明细分页查询", description = "预付（待履约）明细分页查询")
    @PostMapping("/prepayPage")
    public R<PageRes<PrepayVo>> prepayPage(@RequestBody @Valid PrePayPage prePayPage) {
        return R.ok(walletService.prepayPage(prePayPage));
    }


    /**
     * 【接口】预付（待收）运费清单分页查询
     *
     * @param listPage
     */
    @Operation(summary = "预付（待收）运费清单分页查询", description = "预付（待收）运费清单分页查询")
    @PostMapping("/duePay")
    public R<Object> duePay(@RequestBody @Valid ListPage listPage) {
        return R.ok(walletService.duePayList(listPage));
    }


}
