-- Docling conversion results for NAS documents

CREATE TABLE IF NOT EXISTS docling_results (
    id SERIAL PRIMARY KEY,
    storage_path TEXT NOT NULL,
    file_sig VARCHAR(64) NOT NULL DEFAULT '',
    status VARCHAR(32) NOT NULL DEFAULT 'pending',
    options JSONB NOT NULL DEFAULT '{}'::jsonb,
    exports JSONB NOT NULL DEFAULT '{}'::jsonb,
    tables_data JSONB NOT NULL DEFAULT '[]'::jsonb,
    pictures JSONB NOT NULL DEFAULT '[]'::jsonb,
    page_count INT DEFAULT 0,
    metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
    error_text TEXT,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    completed_at TIMESTAMPTZ,
    UNIQUE (storage_path, file_sig)
);

CREATE INDEX IF NOT EXISTS idx_docling_results_path ON docling_results (storage_path);
CREATE INDEX IF NOT EXISTS idx_docling_results_status ON docling_results (status, created_at DESC);
