CREATE TABLE IF NOT EXISTS ai_jobs (
    id           BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    uuid         CHAR(36)        NOT NULL,
    type         ENUM('translate','transcribe','caption','detect_lang') NOT NULL,
    status       ENUM('queued','processing','done','failed') DEFAULT 'queued',
    input_data   JSON            NOT NULL,
    output_data  JSON            DEFAULT NULL,
    error        TEXT            DEFAULT NULL,
    created_at   DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,
    processed_at DATETIME        DEFAULT NULL,
    UNIQUE KEY uq_uuid (uuid),
    INDEX idx_status (status),
    INDEX idx_type_status (type, status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
