package com.czg.controller.pay;

import com.czg.annotation.Debounce;
import com.czg.order.dto.MkDistributionPayDTO;
import com.czg.resp.CzgResult;
import com.czg.service.order.service.DistributionPayService;
import com.czg.utils.AssertUtil;
import com.czg.utils.ServletUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 分销员开通
 *
 * @author ww
 * @description
 */
@RestController
@RequestMapping("/pay/distribution")
public class DistributionPayController {
    @Resource
    private DistributionPayService payService;

    /**
     * 小程序支付
     * payType 必填  支付方式，ALIPAY 支付宝，WECHAT 微信
     * openId  必填
     */
    @PostMapping("/ltPayOrder")
    @Debounce(value = "#payParam.userId")
    public CzgResult<Map<String, Object>> ltPayOrder(HttpServletRequest request, @Validated @RequestBody MkDistributionPayDTO payParam) {
        return payService.ltPayOrder(ServletUtil.getClientIP(request), payParam);
    }


    /**
     * 运营端小程序余额充值
     * payType 必填  支付方式，ALIPAY 支付宝，WECHAT 微信
     */
    @PostMapping("/mchRecharge")
    @Debounce(value = "#payParam.userId")
    public CzgResult<Map<String, String>> mchRecharge(@Validated @RequestBody MkDistributionPayDTO payParam) {
        AssertUtil.isBlank(payParam.getCode(), "微信code不为空");
        return CzgResult.success(payService.mchRecharge(payParam));
    }
}
