<?php
/**
 * ITSWEBER CMS – Migration 027: Seed Section Types
 *
 * Populates iw_section_types with the 20 built-in section types.
 * Uses INSERT IGNORE so re-running is safe (idempotent).
 *
 * @author    Benny Weber (ITSWEBER)
 * @copyright © ITSWEBER – www.itsweber.de
 * @contact   kontakt@itsweber.de
 */

use App\Database\Migration;

class SeedSectionTypes extends Migration
{
    public function up(): void
    {
        $types = [
            ['hero',              'Hero Banner',            'header',  0, 1],
            ['intro',             'Intro / Textblock',      'content', 1, 2],
            ['features',          'Feature-Items',          'content', 1, 3],
            ['topic_cards',       'Themenkarten',           'content', 1, 4],
            ['highlight_grid',    'Highlight-Grid',         'content', 1, 5],
            ['feature_showcase',  'Feature Showcase',       'content', 1, 6],
            ['service_cards',     'Service-Karten',         'content', 1, 7],
            ['trust_showcase',    'Trust / USP',            'content', 1, 8],
            ['process_steps',     'Prozess-Schritte',       'content', 1, 9],
            ['rating_highlight',  'Bewertungs-Highlight',   'content', 1, 10],
            ['team_section',      'Team-Mitglieder',        'content', 1, 11],
            ['before_after',      'Before/After Slider',    'media',   1, 12],
            ['video_section',     'Video',                  'media',   1, 13],
            ['html_section',      'HTML Freiform',          'media',   1, 14],
            ['social_embed',      'Social Embed',           'media',   1, 15],
            ['gallery_preview',   'Galerie-Vorschau',       'preview', 1, 16],
            ['blog_preview',      'Blog-Vorschau',          'preview', 1, 17],
            ['events_preview',    'Events-Vorschau',        'preview', 1, 18],
            ['cta',               'Call-to-Action',         'action',  1, 19],
            ['site_notice',       'Ankündigungsleiste',     'global',  0, 20],
        ];

        $stmt = "INSERT IGNORE INTO iw_section_types
                    (type_key, label, category, source, allow_multiple, sort_order)
                 VALUES
                    (:type_key, :label, :category, 'core', :allow_multiple, :sort_order)";

        foreach ($types as $type) {
            $this->db->query($stmt, [
                'type_key'       => $type[0],
                'label'          => $type[1],
                'category'       => $type[2],
                'allow_multiple' => $type[3],
                'sort_order'     => $type[4],
            ]);
        }
    }

    public function down(): void
    {
        $this->db->query("
            DELETE FROM iw_section_types WHERE source = 'core'
        ");
    }
}
