-- 002_tool_feedback.sql
-- Target DB: dobetternorge_maindb (the tools' operational DB, via dbnmDb()).
-- Run manually after a mysqldump backup. Idempotent (IF NOT EXISTS).
--
-- Per-tool thumbs up/down + optional "what was missed or wrong" note, captured by
-- the in-result feedback widget (assets/js/tools.js) via api/feedback.php.
-- Metadata + voluntary comment only — NO pasted case content (process-and-forget).
--
-- tool             : tool slug the result came from (ask|summarize|redact|timeline|...)
-- rating           : positive | negative
-- engine           : the engine string that produced the result (best-effort, client-supplied)
-- missed_or_wrong  : short optional free-text note (what the tool missed/got wrong)
-- session_id       : PHP session id (coarse de-dupe / abuse signal), not a user identity

CREATE TABLE IF NOT EXISTS tool_feedback (
    id              INT UNSIGNED NOT NULL AUTO_INCREMENT,
    session_id      VARCHAR(40)  DEFAULT NULL,
    tool            VARCHAR(30)  NOT NULL,
    rating          ENUM('positive','negative') NOT NULL,
    missed_or_wrong TEXT         DEFAULT NULL,
    engine          VARCHAR(60)  DEFAULT NULL,
    created_at      TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    KEY idx_tool (tool),
    KEY idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
