import logging

logger = logging.getLogger(__name__)

class ThresholdManager:
    def __init__(self, upper_threshold, lower_threshold, hysteresis_upper, hysteresis_lower):
        self.upper_threshold = upper_threshold
        self.lower_threshold = lower_threshold
        self.hysteresis_upper = hysteresis_upper
        self.hysteresis_lower = hysteresis_lower
        self.upper_threshold_breached = False
        self.lower_threshold_breached = False

    def should_scale_up(self, current_value):
        if current_value >= self.upper_threshold and not self.upper_threshold_breached:
            if self.upper_threshold + self.hysteresis_upper <= current_value:
                self.upper_threshold_breached = True
                return True
            else:
                logger.warning(
                    "Hysteresis prevents scale up. Current value: %s, Upper Threshold: %s, Hysteresis Upper: %s, Reason: Value within hysteresis range.",
                    current_value, self.upper_threshold, self.hysteresis_upper
                )
                return False
        return False

    def should_scale_down(self, current_value):
        if current_value <= self.lower_threshold and not self.lower_threshold_breached:
            if self.lower_threshold - self.hysteresis_lower >= current_value:
                self.lower_threshold_breached = True
                return True
            else:
                logger.warning(
                    "Hysteresis prevents scale down. Current value: %s, Lower Threshold: %s, Hysteresis Lower: %s, Reason: Value within hysteresis range.",
                    current_value, self.lower_threshold, self.hysteresis_lower
                )
                return False
        return False

    def reset_upper_threshold(self):
        self.upper_threshold_breached = False

    def reset_lower_threshold(self):
        self.lower_threshold_breached = False