CREATE TABLE IF NOT EXISTS `questions` (
    `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    `uuid` CHAR(36) NOT NULL,
    `title` VARCHAR(280) NOT NULL,
    `body` TEXT NULL,
    `image_path` VARCHAR(500) NULL,
    `status` ENUM('draft','scheduled','published','archived') NOT NULL DEFAULT 'draft',
    `scheduled_date` DATE NULL,
    `published_at` DATETIME NULL,
    `created_by_user_id` BIGINT UNSIGNED NULL,
    `suggested_by_user_id` BIGINT UNSIGNED NULL,
    `category` VARCHAR(40) NULL,
    `is_ai_generated` TINYINT(1) NOT NULL DEFAULT 0,
    `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `uniq_questions_uuid` (`uuid`),
    KEY `idx_questions_status_date` (`status`, `scheduled_date`),
    KEY `idx_questions_published_at` (`published_at`),
    CONSTRAINT `fk_questions_created_by` FOREIGN KEY (`created_by_user_id`) REFERENCES `users`(`id`) ON DELETE SET NULL,
    CONSTRAINT `fk_questions_suggested_by` FOREIGN KEY (`suggested_by_user_id`) REFERENCES `users`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
