package com.jay.monitor.data.server.report.alert.rule;

import com.jay.monitor.data.core.model.serializable.base.BaseDTO;
import com.jay.monitor.data.server.enums.AlertRuleEnums;
import com.jay.monitor.data.server.models.config.AlertRuleConfigModel;
import com.jay.monitor.data.server.store.ConfigStoreManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Module 告警
 * @Description 状态告警
 * @Author liukaixiong
 * @Date 2021/1/14 16:17
 */
@Component
public class StatusAlertRule implements AlertRule {

    @Autowired
    private ConfigStoreManager configStoreManager;

    @Override
    public AlertRuleEnums ruleType() {
        return AlertRuleEnums.STATUS;
    }

    @Override
    public boolean isTrigger(BaseDTO baseDTO) {

        if (!this.configStoreManager.alertEnable()) {
            return false;
        }
        Integer status = baseDTO.getStatus();
        AlertRuleConfigModel alertConfigModel = configStoreManager.getAlertRuleConfigModel(baseDTO.getType());
        if (alertConfigModel != null) {
            if (alertConfigModel.getStatusList().contains(status)) {
                return true;
            }
        }
        return false;
    }

}
