-- Tracks every RPO check cycle where a workstation job was suppressed
-- because the device was offline (last_seen older than its backup interval).
-- Used for auditing, reporting, and the Claude Code skill.

CREATE TABLE IF NOT EXISTS veeam_rpo_offline_log (
  id                    SERIAL PRIMARY KEY,
  job_instance_uid      VARCHAR(255) NOT NULL,
  job_name              TEXT NOT NULL,
  org_name              TEXT NOT NULL,
  rmm_hostname          TEXT NOT NULL,
  rmm_site_name         TEXT NOT NULL,
  device_type_category  TEXT NOT NULL,
  rmm_last_seen         TIMESTAMPTZ,
  hours_offline         NUMERIC(10,2) NOT NULL,
  backup_interval_hours INTEGER NOT NULL,
  checked_at            TIMESTAMPTZ DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_veeam_rpo_offline_log_job        ON veeam_rpo_offline_log(job_instance_uid);
CREATE INDEX IF NOT EXISTS idx_veeam_rpo_offline_log_checked_at ON veeam_rpo_offline_log(checked_at);
CREATE INDEX IF NOT EXISTS idx_veeam_rpo_offline_log_hostname   ON veeam_rpo_offline_log(rmm_hostname);
