package com.jay.monitor.data.server.store;

import com.jay.monitor.data.core.enums.MsgTypeEnums;
import com.jay.monitor.data.server.config.props.AlertProperties;
import com.jay.monitor.data.server.enums.AlertMsgEnums;
import com.jay.monitor.data.server.models.config.AlertConfigModel;
import com.jay.monitor.data.server.models.config.AlertRuleConfigModel;
import com.jay.monitor.data.server.utils.DataUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @Module 配置模块
 * @Description 基于本地文件配置
 * @Author liukaixiong
 * @Date 2021/1/15 10:55
 */
public class DefaultLocalConfigManager implements ConfigStoreManager {

    @Autowired
    private AlertProperties alertProperties;

    @Override
    public String getConsoleUrl() {
        return alertProperties.getConsoleUrl();
    }

    @Override
    public String getLogMonitorUrl() {
        return alertProperties.getLogMonitorUrl();
    }

    @Override
    public String getServerLogConsole() {
        return alertProperties.getServerLogConsole();
    }

    @Override
    public boolean alertEnable() {
        return DataUtils.getDefaultValue(alertProperties.isEnable(), false);
    }

    @Override
    public AlertConfigModel getAlertConfigModel(AlertMsgEnums alertMsgEnums) {
        Map<AlertMsgEnums, AlertConfigModel> alertType = alertProperties.getAlertType();
        return alertType.get(alertMsgEnums);
    }

    @Override
    public Long getAlertIntervalMinutes() {
        return TimeUnit.MINUTES.toMillis(DataUtils.getDefaultValue(alertProperties.getAlertIntervalMinutes(), 1L));
    }

    @Override
    public AlertRuleConfigModel getAlertRuleConfigModel(MsgTypeEnums msgTypeEnums) {
        Map<MsgTypeEnums, AlertRuleConfigModel> alertRuleConfigMap = alertProperties.getAlertRuleConfigMap();
        return alertRuleConfigMap.get(msgTypeEnums);
    }
}
