package com.sonic.lion.controller.web;

import com.sonic.common.auth.domains.Session;
import com.sonic.common.rpc.Result;
import com.sonic.common.utils.IpAddressUtils;
import com.sonic.lion.domain.req.PreChargeReq;
import com.sonic.lion.domain.resp.PrePaymentResp;
import com.sonic.lion.service.PreChargeHandlerService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 充值预下单
 * @author: code
 * @date: 2025/06/22
 * @Description:
 * @version: 1.0.0
 */
@RestController
public class PreChargeController {

    @Autowired
    private PreChargeHandlerService preChargeHandlerService;

    @ApiOperation(value = "web充值预下单", tags = "充值预下单")
    @PostMapping("/web/pay/trade/pre-charge")
    public Result<PrePaymentResp> preCharge(@RequestBody @Validated PreChargeReq req, @ApiParam(hidden = true) Session session, @ApiParam(hidden = true) HttpServletRequest httpServletRequest) {
        PrePaymentResp resp = preChargeHandlerService.preCharge(session.getUserId(), req, IpAddressUtils.getIpAddress(httpServletRequest));
        return Result.success(resp);
    }

    @ApiOperation(value = "iOS充值预下单", tags = "充值预下单")
    @PostMapping("/web/pay/trade/pre-charge-iap")
    public Result<PrePaymentResp> iapPreCharge(@RequestBody @Validated PreChargeReq req, @ApiParam(hidden = true) Session session, @ApiParam(hidden = true) HttpServletRequest httpServletRequest) {
        PrePaymentResp resp = preChargeHandlerService.iapPreCharge(session.getUserId(), req, IpAddressUtils.getIpAddress(httpServletRequest));
        return Result.success(resp);
    }

    @ApiOperation(value = "Google充值预下单", tags = "充值预下单")
    @PostMapping("/web/pay/trade/pre-charge-google")
    public Result<PrePaymentResp> googlePreCharge(@RequestBody @Validated PreChargeReq req, @ApiParam(hidden = true) Session session, @ApiParam(hidden = true) HttpServletRequest httpServletRequest) {
        PrePaymentResp resp = preChargeHandlerService.googlePreCharge(session.getUserId(), req, IpAddressUtils.getIpAddress(httpServletRequest));
        return Result.success(resp);
    }

}
