<?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 – pfllegbare 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
                ('topic_cards', 'Topic Cards', '" . addslashes(json_encode([
                    'title' => 'Was wir anbieten',
                    'items' => [],
                ], JSON_UNESCAPED_UNICODE)) . "', 0, 7, NOW())
        ");

        // 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
                ('highlight_grid', 'Highlight Grid', '" . addslashes(json_encode([
                    'title' => 'Im Fokus',
                    'items' => [],
                ], JSON_UNESCAPED_UNICODE)) . "', 0, 8, NOW())
        ");
    }

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