-- =====================================================================
-- RENDER SCHEMA — AEP scan jobs
-- Async "scan a project template with After Effects" jobs. A node claims a
-- queued scan, runs scan.jsx against the template, and posts back the result
-- (the same ScanResult JSON the content importer consumes).
-- =====================================================================

SET search_path TO render, public;

CREATE TABLE IF NOT EXISTS scan_jobs (
    id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    project_id  UUID NOT NULL,
    status      TEXT NOT NULL DEFAULT 'queued',   -- queued | running | done | error
    engine      TEXT NOT NULL DEFAULT 'ae-jsx',    -- ae-jsx | go-parser
    result      JSONB,
    error       TEXT,
    node_id     UUID,
    created_at  TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at  TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_scan_jobs_status  ON scan_jobs(status, created_at);
CREATE INDEX IF NOT EXISTS idx_scan_jobs_project ON scan_jobs(project_id, created_at DESC);
