<?php
/**
 * ITSWEBER CMS – Migration 024: Page Sections
 *
 * Creates the iw_page_sections table that stores placed section
 * instances for the page builder (initially homepage only).
 *
 * @author    Benny Weber (ITSWEBER)
 * @copyright © ITSWEBER – www.itsweber.de
 * @contact   kontakt@itsweber.de
 */

use App\Database\Migration;

class CreatePageSections extends Migration
{
    public function up(): void
    {
        $this->db->query("
            CREATE TABLE IF NOT EXISTS iw_page_sections (
                id              INT AUTO_INCREMENT PRIMARY KEY,
                page_context    VARCHAR(100) NOT NULL DEFAULT 'homepage',
                section_type    VARCHAR(50)  NOT NULL,
                instance_label  VARCHAR(255) DEFAULT NULL,
                content         LONGTEXT     DEFAULT NULL,
                is_active       TINYINT(1)   DEFAULT 1,
                sort_order      INT          DEFAULT 0,
                created_at      DATETIME     DEFAULT CURRENT_TIMESTAMP,
                updated_at      DATETIME     DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                INDEX idx_context_order (page_context, sort_order),
                INDEX idx_section_type (section_type)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
        ");
    }

    public function down(): void
    {
        $this->db->query("DROP TABLE IF EXISTS iw_page_sections");
    }
}
