package com.yunfeiyun.agmp.common.utils;


import com.yunfeiyun.agmp.common.enums.RedisCacheKey;
import com.yunfeiyun.agmp.common.framework.manager.RedisCacheManager;
import com.yunfeiyun.agmp.common.utils.spring.SpringUtils;

public class ConfigUtils {
    private static final String SYS_CONFIG_PREFIX = "sys_config:";


    public static String getConfigValue(String configKey){
        return SpringUtils.getBean(RedisCacheManager.class).getCacheObject(RedisCacheKey.SYS_CONFIG,configKey);
    }


    public enum ConfigKeyEnum {
        STOCK_CHANGE_BIZ_LOCK("stock_change_biz_lock","库存变动业务锁"),
        PROJECT_LOCATION_WEATHER_PARAM("project_location_weather_param","项目所在城市经纬度"),
        TRACE_CODE_TPL_DEFAULT_ID("trace_code_tpl_default_id","默认溯源码模板标识"),
        INIT_PASSWORD("init_password","用户管理-账号初始密码"),
        PORTAL_THEME("portal_theme","管理平台主题"),
        INIT_SYSMENU("init_sysmenu","子系统菜单配置项"),
        CAPTCHA_ENABLED("captcha_enabled","账号自助-验证码开关"),
        ;

        private final String key;
        private final String label;


        ConfigKeyEnum(String key, String label)
        {
            this.key = key;
            this.label = label;

        }

        public String getKey()
        {
            return key;
        }
        public String getLabel(){
            return label;
        }

        public static String valueOfCode(String key){
            return SpringUtils.getBean(RedisCacheManager.class).getCacheObject(RedisCacheKey.SYS_CONFIG,key);
        }

        public String valueOf(){
            return SpringUtils.getBean(RedisCacheManager.class).getCacheObject(RedisCacheKey.SYS_CONFIG,this.key);
        }

        public boolean equal(String code){
            return this.key.equals(code);
        }
    }

}
