-- Devices being monitored for latency
CREATE TABLE monitoring_devices (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    host VARCHAR(255) NOT NULL,
    label VARCHAR(255) NOT NULL,
    is_active TINYINT(1) NOT NULL DEFAULT 1,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    UNIQUE KEY uq_monitoring_devices_host (host)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Individual latency samples captured by the watcher
CREATE TABLE monitoring_latency_log (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    device_id INT UNSIGNED NOT NULL,
    latency_ms INT UNSIGNED NULL,
    status ENUM('up','down','unknown') NOT NULL,
    checked_at DATETIME NOT NULL,
    PRIMARY KEY (id),
    KEY idx_monitoring_latency_device_checked (device_id, checked_at),
    CONSTRAINT fk_monitoring_latency_device
        FOREIGN KEY (device_id) REFERENCES monitoring_devices(id)
        ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
