-- Executar uma vez no MySQL da conta cPanel
-- Base de dados: webhs_lp (criar antes via cPanel → MySQL Databases)

CREATE TABLE IF NOT EXISTS diagnostico_queue (
    id            INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    source        VARCHAR(50)  NOT NULL DEFAULT 'wordpress',  -- slug da LP
    nome          VARCHAR(100) NOT NULL,
    email         VARCHAR(150) NOT NULL,
    url           VARCHAR(500) NOT NULL,
    ip            VARCHAR(45)  NOT NULL,
    status        ENUM('pending','processing','done','error') NOT NULL DEFAULT 'pending',
    result        JSON         NULL,
    report_hash   CHAR(32)     NULL,
    report_expires DATETIME    NULL,
    error_msg     TEXT         NULL,
    created_at    DATETIME     NOT NULL DEFAULT NOW(),
    processed_at  DATETIME     NULL,
    INDEX idx_status  (status),
    INDEX idx_email   (email),
    INDEX idx_ip      (ip),
    INDEX idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Se a tabela já existir:
-- ALTER TABLE diagnostico_queue
--   ADD COLUMN report_hash     CHAR(32)  NULL AFTER result,
--   ADD COLUMN report_expires  DATETIME  NULL AFTER report_hash,
--   ADD INDEX  idx_ip (ip);
