package com.czg;

import com.czg.constant.PayChannelCst;
import com.czg.impl.NativePayAdapter;
import com.czg.impl.PolyPayAdapter;

import java.util.HashMap;
import java.util.Map;

/**
 * 支付适配器工厂
 *
 * @author ww
 */
public class PayAdapterFactory {

    private static final Map<String, PayAdapter> ADAPTER_MAP = new HashMap<>();

    static {
        ADAPTER_MAP.put(PayChannelCst.POLY, new PolyPayAdapter());
        ADAPTER_MAP.put(PayChannelCst.NATIVE, new NativePayAdapter());
    }


    /**
     * 获取支付适配器
     *
     * @param channel 支付渠道，仅支持 {@link PayChannelCst}
     */
    public static PayAdapter getAdapter(String channel) {
        PayAdapter adapter = ADAPTER_MAP.get(channel);
        if (adapter == null) {
            throw new IllegalStateException("支付渠道未注册适配器: " + channel);
        }
        return adapter;
    }


}
