<?php

use App\Database\Migration;

class CreatePagesTable extends Migration
{
    public function up(): void
    {
        $this->db->query("
            CREATE TABLE IF NOT EXISTS iw_pages (
                id INT AUTO_INCREMENT PRIMARY KEY,
                title VARCHAR(255) NOT NULL,
                slug VARCHAR(255) NOT NULL UNIQUE,
                content LONGTEXT,
                template VARCHAR(100) NOT NULL DEFAULT 'page',
                status ENUM('draft','published') NOT NULL DEFAULT 'draft',
                sort_order INT NOT NULL DEFAULT 0,
                is_homepage TINYINT(1) NOT NULL DEFAULT 0,
                seo_title VARCHAR(255) DEFAULT NULL,
                seo_description TEXT DEFAULT NULL,
                created_by INT DEFAULT NULL,
                created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
                updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                INDEX idx_status (status),
                INDEX idx_slug (slug),
                INDEX idx_homepage (is_homepage)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
        ");
    }

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