package com.zhongshu.card.server.core.controller.pay.balance;

import com.github.microservice.pay.client.ret.ResultContent;
import com.zhongshu.card.client.model.pay.QueryRechargeParam;
import com.zhongshu.card.client.model.pay.RechargeParam;
import com.zhongshu.card.server.core.service.pay.BalancePayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("balance/recharge")
@Tag(name = "余额支付", description = "余额支付充值接口")
public class RechargeController {

    @Autowired
    BalancePayService balancePayService;

    @Operation(summary = "余额充值", description = "余额充值")
    @RequestMapping(value = "recharge", method = RequestMethod.POST)
    public Object recharge(@RequestBody RechargeParam param){
        return balancePayService.recharge(param);
    }

    @Operation(summary = "查询充值记录", description = "查询充值记录")
    @RequestMapping(value = "queryRechargeOrder", method = RequestMethod.POST)
    public Object queryRechargeOrder(@RequestBody QueryRechargeParam param){
        return balancePayService.queryRechargeOrder(param);
    }

    @Operation(summary = "查询用户余额", description = "查询用户余额")
    @RequestMapping(value = "queryUserBalance", method = RequestMethod.GET)
    public Object queryUserBalance(@RequestParam(value = "projectOid", required = false) String projectOid, @RequestParam(value = "userId", required = false) String userId){
        return balancePayService.queryUserBalance(projectOid, userId);
    }

    @Operation(summary = "查询充值订单详情", description = "查询充值订单详情")
    @RequestMapping(value = "queryInfo", method = RequestMethod.GET)
    public Object queryInfo(@RequestParam("orderNo") String orderNo){
        return balancePayService.queryInfo(orderNo);
    }

    @Operation(summary = "关闭充值订单", description = "关闭充值订单（只有待支付状态时可以关闭）")
    @RequestMapping(value = "close", method = RequestMethod.GET)
    public Object close(@RequestParam("orderNo") String orderNo){
        return balancePayService.close(orderNo);
    }

    @Operation(summary = "获取openid")
    @GetMapping(value = "getOpenid")
    public Object getOpenid(@Parameter(name = "jscode") @RequestParam(name = "jscode") String jscode) {
        return balancePayService.getOpenid(jscode);
    }
}
