# aiva/downscale_detection/config.py

# Example configuration for downscale patterns
# This can be loaded from a file (e.g., JSON or YAML) in a real application

DEFAULT_DOWNSCALE_PATTERNS = [
    {
        "name": "High CPU Utilization Followed by Memory Exhaustion",
        "description": "Detects a pattern where CPU usage spikes above a threshold,
                        followed by a memory exhaustion event within a specified timeframe.",
        "events": [
            {
                "type": "cpu_utilization",
                "threshold": 90,  # Percentage
                "operator": ">=",
                "window": 60,  # seconds
                "required": True
            },
            {
                "type": "memory_exhaustion",
                "window": 300, # seconds
                "required": True
            }
        ],
        "consequence": "Scale down application instances to reduce load."
    },
    {
        "name": "Increased Latency and Error Rate",
        "description": "Detects a pattern where latency increases above a threshold,
                        followed by an increased error rate within a specified timeframe.",
        "events": [
            {
                "type": "latency",
                "threshold": 500,  # milliseconds
                "operator": ">=",
                "window": 60,  # seconds
                "required": True
            },
            {
                "type": "error_rate",
                "threshold": 5,  # Percentage
                "operator": ">=",
                "window": 300, # seconds
                "required": True
            }
        ],
        "consequence": "Scale down less critical services to prioritize core functionality."
    }
]

# Function to load configurations from a file (example)
def load_config(file_path):
    # In a real implementation, this would read from a JSON or YAML file
    # For simplicity, we return the default config
    print(f"Loading config from {file_path} (simulated)")
    return DEFAULT_DOWNSCALE_PATTERNS
