<?php

use App\Database\Migration;

/**
 * Phase 6c – Add topic_cards and highlight_grid homepage sections.
 *
 * Uses INSERT IGNORE so existing rows (from seed or previous runs) are never
 * duplicated.  Does not alter any existing table columns or data.
 */
class AddNewHomepageSections extends Migration
{
    public function up(): void
    {
        // topic_cards – pflegbare Themenkarten mit Icon/Titel/Text/Link
        $this->db->query(
            "INSERT IGNORE INTO iw_homepage_sections
                (section_key, title, content, is_active, sort_order, updated_at)
            VALUES
                (:key, :title, :content, :active, :sort, NOW())",
            [
                'key'     => 'topic_cards',
                'title'   => 'Topic Cards',
                'content' => json_encode(['title' => 'Was wir anbieten', 'items' => []], JSON_UNESCAPED_UNICODE),
                'active'  => 0,
                'sort'    => 7,
            ]
        );

        // highlight_grid – größere Highlight-Kacheln mit Titel/Text/Icon/Link
        $this->db->query(
            "INSERT IGNORE INTO iw_homepage_sections
                (section_key, title, content, is_active, sort_order, updated_at)
            VALUES
                (:key, :title, :content, :active, :sort, NOW())",
            [
                'key'     => 'highlight_grid',
                'title'   => 'Highlight Grid',
                'content' => json_encode(['title' => 'Im Fokus', 'items' => []], JSON_UNESCAPED_UNICODE),
                'active'  => 0,
                'sort'    => 8,
            ]
        );
    }

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