CREATE TABLE IF NOT EXISTS alerts (
    alert_id INT AUTO_INCREMENT PRIMARY KEY,
    node_id INT NOT NULL,
    metric_name VARCHAR(50) NOT NULL,
    actual_value DECIMAL(10, 2) NOT NULL,
    threshold_value DECIMAL(10, 2) NOT NULL,
    status ENUM('active', 'acknowledged', 'resolved') NOT NULL DEFAULT 'active',
    timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (node_id) REFERENCES nodes(id)
);

-- Seed some sample alerts
INSERT INTO alerts (node_id, metric_name, actual_value, threshold_value, status) VALUES
(1, 'temperature', 28.5, 25.0, 'active'),
(3, 'humidity', 65.0, 60.0, 'active'),
(4, 'co2', 1200, 1000, 'acknowledged'),
(2, 'temperature', 29.0, 25.0, 'resolved'),
(4, 'humidity', 68.0, 60.0, 'active');