-- =====================================================================
-- RENDER SCHEMA — Part 25: font distribution to render nodes
-- Admin requests a font to be installed on all nodes; each node-agent installs
-- it and reports status, so the admin can verify per-node installation.
-- =====================================================================

SET search_path TO render, public;

-- A font that should be present on every render node.
CREATE TABLE IF NOT EXISTS font_requests (
    id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    name        TEXT NOT NULL,
    system_name TEXT,                 -- the OS/PostScript family name AE looks up
    file_url    TEXT NOT NULL,        -- .ttf/.otf URL the node downloads
    created_at  TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- Per-node install status for a requested font.
CREATE TABLE IF NOT EXISTS node_fonts (
    node_id         UUID NOT NULL,
    font_request_id UUID NOT NULL REFERENCES font_requests(id) ON DELETE CASCADE,
    status          TEXT NOT NULL DEFAULT 'Pending',  -- Pending | Installed | Failed
    error           TEXT,
    updated_at      TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    PRIMARY KEY (node_id, font_request_id)
);

CREATE INDEX IF NOT EXISTS idx_node_fonts_request ON node_fonts (font_request_id);
