-- AI Landing Pages table
-- Supports multiple landing pages per product

CREATE TABLE IF NOT EXISTS `ai_landing_pages` (
  `id`           INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `product_id`   INT(10) UNSIGNED NOT NULL,
  `name`         VARCHAR(255) NOT NULL COMMENT 'Internal name for admin',
  `slug`         VARCHAR(255) NOT NULL COMMENT 'URL-friendly identifier',
  `html_content` LONGTEXT DEFAULT NULL COMMENT 'Full generated HTML of the landing page',
  `conversation` LONGTEXT DEFAULT NULL COMMENT 'JSON array of chat history [{role,content}]',
  `status`       ENUM('draft','published') NOT NULL DEFAULT 'draft',
  `source_mode`  VARCHAR(20) NOT NULL DEFAULT 'manual' COMMENT 'manual or image',
  `source_image` VARCHAR(255) DEFAULT NULL COMMENT 'Uploaded screenshot/design path',
  `analysis_json` LONGTEXT DEFAULT NULL COMMENT 'Vision analysis result JSON',
  `structure_json` LONGTEXT DEFAULT NULL COMMENT 'Normalized layout structure JSON',
  `agent_trace`  LONGTEXT DEFAULT NULL COMMENT 'Plan/generate/evaluate/improve trace',
  `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 `uq_slug` (`slug`),
  KEY `idx_product_id` (`product_id`),
  KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
