package com.jsowell.adapay.factory;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jsowell.adapay.config.AbstractAdapayConfig;
import com.jsowell.common.util.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * adapay配置工厂类
 */
public class AdapayConfigFactory {
    /*
     key为微信小程序appId, value为对应的汇付支付配置
     */
    private static Map<String, AbstractAdapayConfig> configMap = Maps.newHashMap();

    /**
     * 注册
     * @param str
     * @param handler
     */
    public static void register(String str, AbstractAdapayConfig handler) {
        if (StringUtils.isBlank(str) || Objects.isNull(handler)) {
            return;
        }
        configMap.put(str, handler);
    }

    /**
     * 获取
     * @param wechatAppId 微信小程序appId
     * @return 对应的汇付支付配置
     */
    public static AbstractAdapayConfig getConfig(String wechatAppId) {
        return configMap.get(wechatAppId);
    }

    /**
     * 获取全部
     */
    public static List<AbstractAdapayConfig> getAllConfig() {
        return Lists.newArrayList(configMap.values());
    }
}
