<?php

use App\Database\Migration;

/**
 * Migration 018 – Add plugin homepage section types
 * Phase 2.4.0 – Video Section, HTML Editor Section, Team Section
 *
 * Uses INSERT IGNORE to be safely re-runnable.
 */
class AddPluginHomepageSections extends Migration
{
    public function up(): void
    {
        // Add video_section
        $this->db->query(
            "INSERT IGNORE INTO iw_homepage_sections
                (section_key, title, content, is_active, sort_order) VALUES
                (:key, :title, :content, :active, :sort)",
            [
                'key'     => 'video_section',
                'title'   => 'Video / YouTube',
                'content' => json_encode(['title' => '', 'subtitle' => '', 'video_type' => 'youtube', 'video_url' => '', 'poster_image' => '', 'cta_text' => '', 'cta_url' => '', 'color_scheme' => '']),
                'active'  => 0,
                'sort'    => 100,
            ]
        );

        // Add html_section
        $this->db->query(
            "INSERT IGNORE INTO iw_homepage_sections
                (section_key, title, content, is_active, sort_order) VALUES
                (:key, :title, :content, :active, :sort)",
            [
                'key'     => 'html_section',
                'title'   => 'HTML / Editor Content',
                'content' => json_encode(['title' => '', 'subtitle' => '', 'content_html' => '', 'color_scheme' => '']),
                'active'  => 0,
                'sort'    => 110,
            ]
        );

        // Add team_section
        $this->db->query(
            "INSERT IGNORE INTO iw_homepage_sections
                (section_key, title, content, is_active, sort_order) VALUES
                (:key, :title, :content, :active, :sort)",
            [
                'key'     => 'team_section',
                'title'   => 'Team',
                'content' => json_encode(['title' => '', 'subtitle' => '', 'members' => [], 'columns' => '3', 'color_scheme' => '']),
                'active'  => 0,
                'sort'    => 120,
            ]
        );
    }

    public function down(): void
    {
        $this->db->query("DELETE FROM iw_homepage_sections WHERE section_key IN ('video_section','html_section','team_section')");
    }
}
