package com.qqchen.deploy.backend.framework.monitor;

import com.qqchen.deploy.backend.framework.enums.MonitorAlertLevelEnum;

import java.math.BigDecimal;

/**
 * 服务器阈值检测器抽象基类
 * 提供通用的阈值检测逻辑
 *
 * @author qqchen
 * @since 2025-12-07
 */
public abstract class AbstractServerThresholdChecker<T> implements IServerThresholdChecker<T> {
    
    @Override
    public MonitorAlertLevelEnum checkThreshold(BigDecimal currentValue, 
                                                 BigDecimal warningThreshold, 
                                                 BigDecimal criticalThreshold) {
        if (currentValue == null) {
            return null;
        }
        
        // 检查是否超过严重阈值
        if (criticalThreshold != null && currentValue.compareTo(criticalThreshold) >= 0) {
            return MonitorAlertLevelEnum.CRITICAL;
        }
        
        // 检查是否超过警告阈值
        if (warningThreshold != null && currentValue.compareTo(warningThreshold) >= 0) {
            return MonitorAlertLevelEnum.WARNING;
        }
        
        // 未超过阈值
        return null;
    }
}
