package com.czg;

import com.czg.exception.CzgException;
import com.czg.pay.*;
import com.czg.third.alipay.AlipayIsvPayManager;
import com.czg.third.wechat.WechatPayManager;

import java.util.Map;

/**
 * @author yjjie
 * @date 2026/1/9 11:24
 */
public class PayManager {

    /**
     * jsapi支付
     *
     * @param paramsDto 参数
     * @return 结果
     */
    public static Map<String, Object> jsapiPay(CzgPayBaseReq paramsDto, NativeMerchantDTO merchantDTO) {
        if (PayCst.Type.WECHAT.equals(paramsDto.getPayType())) {
            return WechatPayManager.jsapiPay(null, paramsDto, merchantDTO);
        } else if (PayCst.Type.ALIPAY.equals(paramsDto.getPayType())) {
            return AlipayIsvPayManager.jsapiPay(null, paramsDto, merchantDTO);
        } else {
            throw new CzgException("不支持的支付平台");
        }
    }

    /**
     * 条码支付
     *
     * @param paramsDto 参数
     * @return 结果
     */
    public static Map<String, Object> barPay(CzgPayBaseReq paramsDto, NativeMerchantDTO merchantDTO) {
        if (PayCst.Type.WECHAT.equals(paramsDto.getPayType())) {
            return WechatPayManager.barPay(null, paramsDto, merchantDTO);
        } else if (PayCst.Type.ALIPAY.equals(paramsDto.getPayType())) {
            return AlipayIsvPayManager.barPay(null, paramsDto, merchantDTO);
        } else {
            throw new CzgException("不支持的支付平台");
        }
    }

    /**
     * 查询订单状态
     */
    public static QueryOrderRespDTO queryOrderStatus(String platform, String orderNo, NativeMerchantDTO merchantDTO) {
        if (PayCst.Type.WECHAT.equals(platform)) {
            return WechatPayManager.queryOrder(null, orderNo, merchantDTO);
        } else if (PayCst.Type.ALIPAY.equals(platform)) {
            return AlipayIsvPayManager.queryOrder(null, orderNo, merchantDTO);
        } else {
            throw new CzgException("不支持的支付平台");
        }
    }

    /**
     * 退款
     */
    public static RefundRespDTO refund(CzgRefundReq paramsDto, String notifyUrl, NativeMerchantDTO merchantDTO) {
        if (PayCst.Type.WECHAT.equals(paramsDto.getPlatform())) {
            return WechatPayManager.refundOrder(null, paramsDto, notifyUrl, merchantDTO);
        } else if (PayCst.Type.ALIPAY.equals(paramsDto.getPlatform())) {
            return AlipayIsvPayManager.refundOrder(null, paramsDto, notifyUrl, merchantDTO);
        } else {
            throw new CzgException("不支持的支付平台");
        }
    }

    public static void main(String[] args) {
    }
}
