<?php

/**
 * Migration 054: Register premium theme-bound section types
 *
 * Adds 4 new section types for premium themes:
 * - course_schedule (Pulse theme)
 * - tournament (Nexus theme)
 * - high_score (Arcade theme)
 * - code_showcase (Terminal theme)
 */

use App\Database\Migration;

class RegisterPremiumThemeSections extends Migration
{
    public function up(): void
    {
        $sections = [
            [
                'type_key'       => 'course_schedule',
                'label'          => 'Kursplan',
                'description'    => 'Fitness-Kurskarten mit Kategorie, Dauer und Zeitplan',
                'category'       => 'content',
                'icon_svg'       => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>',
                'source'         => 'theme',
                'theme_slug'     => 'pulse',
                'allow_multiple' => 1,
                'is_available'   => 1,
                'sort_order'     => 30,
            ],
            [
                'type_key'       => 'tournament',
                'label'          => 'Turniere',
                'description'    => 'Turnierliste mit Game-Tags, Preisgeld und Status',
                'category'       => 'content',
                'icon_svg'       => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M6 9H4.5a2.5 2.5 0 0 1 0-5H6"/><path d="M18 9h1.5a2.5 2.5 0 0 0 0-5H18"/><path d="M4 22h16"/><path d="M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20 7 22"/><path d="M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20 17 22"/><path d="M18 2H6v7a6 6 0 0 0 12 0V2Z"/></svg>',
                'source'         => 'theme',
                'theme_slug'     => 'nexus',
                'allow_multiple' => 1,
                'is_available'   => 1,
                'sort_order'     => 31,
            ],
            [
                'type_key'       => 'high_score',
                'label'          => 'High Scores',
                'description'    => 'Retro-Bestenliste mit Rang, Spieler und Punktzahl',
                'category'       => 'content',
                'icon_svg'       => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M12 15l-2 5l9-11h-5l2-5l-9 11z"/></svg>',
                'source'         => 'theme',
                'theme_slug'     => 'arcade',
                'allow_multiple' => 1,
                'is_available'   => 1,
                'sort_order'     => 32,
            ],
            [
                'type_key'       => 'code_showcase',
                'label'          => 'Code Showcase',
                'description'    => 'Tabbed code display with syntax highlighting',
                'category'       => 'content',
                'icon_svg'       => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>',
                'source'         => 'theme',
                'theme_slug'     => 'terminal',
                'allow_multiple' => 1,
                'is_available'   => 1,
                'sort_order'     => 33,
            ],
        ];

        foreach ($sections as $section) {
            $exists = $this->db->fetch(
                "SELECT id FROM iw_section_types WHERE type_key = ? LIMIT 1",
                [$section['type_key']]
            );
            if (!$exists) {
                $this->db->insert('iw_section_types', $section);
            }
        }
    }

    public function down(): void
    {
        $this->db->query(
            "DELETE FROM iw_section_types WHERE type_key IN ('course_schedule', 'tournament', 'high_score', 'code_showcase')"
        );
    }
}
