package com.cyksj.config;

import com.cyksj.common.exception.BusinessRuntimeException;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author chan
 * @className WeChatFactory
 * @description 配置
 * @date 2020/9/1 4:51 下午
 */
public class WeChatFactory {
    private static Map<String, BaseWeChatConfig> strategyBean = new ConcurrentHashMap<>();

    /**
     * 初始化
     *
     * @param appId
     * @return
     */
    public static BaseWeChatConfig getWeChatConfigStrategy(String appId) {
        if (StringUtils.isEmpty(appId)) {
            throw BusinessRuntimeException.getInstance("appid错误");
        }
        BaseWeChatConfig baseWeChatConfig = strategyBean.get(appId);
        Objects.requireNonNull(baseWeChatConfig, "appid错误");
        return baseWeChatConfig;
    }

    public static void add(BaseWeChatConfig baseWeChatConfig) {
        strategyBean.put(baseWeChatConfig.getAppid(), baseWeChatConfig);
    }

}
