-- =============================================================
--  PATCH v1.3.0 — New Field Types + Conditional Logic + Description Blocks
-- =============================================================
--  Run this SQL on your database BEFORE uploading the new files.
--  Safe to run multiple times (IF NOT EXISTS / IF NOT EXISTS logic).
--
--  Changes:
--    - fields.options         : JSON array of options for select/radio/checkbox
--    - fields.conditions      : JSON array of conditional display rules
--    - form_text_blocks table : Rich-text description blocks per form page
-- =============================================================

-- 1. Add `options` column (stores JSON for select/radio/checkbox options)
ALTER TABLE `fields`
    ADD COLUMN IF NOT EXISTS `options` TEXT NULL DEFAULT NULL;

-- 2. Add `conditions` column (stores JSON for conditional logic rules)
ALTER TABLE `fields`
    ADD COLUMN IF NOT EXISTS `conditions` TEXT NULL DEFAULT NULL;

-- 3. Create form_text_blocks table (rich-text blocks per form page)
CREATE TABLE IF NOT EXISTS `form_text_blocks` (
    `id`         INT AUTO_INCREMENT PRIMARY KEY,
    `form_id`    INT NOT NULL,
    `page_id`    INT NOT NULL,
    `title`      VARCHAR(255) DEFAULT '',
    `content`    MEDIUMTEXT,
    `sort_order` INT DEFAULT 0,
    `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    INDEX `idx_form_text_blocks_form` (`form_id`),
    INDEX `idx_form_text_blocks_page` (`page_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- =============================================================
--  Done. No data migration required — existing records unaffected.
-- =============================================================
