package com.cyksj.config.wxlogin;

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;

/**
 * 项目名: yhlxj
 * 文件名: WxOpenPlatFactory
 * 创建者: JavaZou
 * 创建时间:2023/9/27 18:33
 */
public class WxOpenPlatFactory {

	private static Map<String, BaseWxOpenPlatConfig> strategyBean = new ConcurrentHashMap<>();

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

	public static void add(BaseWxOpenPlatConfig baseWeChatConfig) {
		strategyBean.put(baseWeChatConfig.getAppId(), baseWeChatConfig);
	}
}
