package com.purui.prims.common.pojo;

import org.apache.commons.lang3.StringUtils;

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

/**
 * 系统默认全局配置
 *
 * @author charlie
 * @date 2024/8/1
 */
public class GlobalAppData {

    Map<String, Object> config;

    private GlobalAppData() {
        config = new HashMap<>(20);
    }

    private static GlobalAppData INSTANCE = null;
    public static GlobalAppData getInstance() {
        if (INSTANCE == null) {
            synchronized (GlobalAppData.class) {
                if (INSTANCE == null) {
                    INSTANCE = new GlobalAppData();
                }
            }
        }
        return INSTANCE;
    }

    public void setConfig(String key, Object value) {
        config.put(key, value);
    }

    /**
     * 获取配置，不存在时，默认为空字符串
     * @author charlie
     * @date   2024/8/1
     */
    public Object getConfig(String key) {
        Object value = config.get(key);
        if (value == null) {
            value = "";
        }
        return value;
    }

    public String getIV() {
        String iv = getString("IV");
        if (StringUtils.isEmpty(iv)) {
            iv = "puruiprims@bicom";
        }
        return iv;
    }

    public String getString(String key) {
        return getConfig(key).toString();
    }

    public boolean exists(String key) {
        return config.containsKey(key);
    }

}
