<?php

use App\Database\Migration;

/**
 * Phase 6d – Add global branding settings.
 *
 * Adds new settings rows for the CMS-wide branding system:
 *   logo_header      – separate header logo (path relative to /uploads/)
 *   logo_footer      – separate footer logo (path relative to /uploads/)
 *   logo_alt         – shared alt text for both logos
 *   logo_header_mode – display mode for header logo ('original' | 'filtered')
 *   logo_footer_mode – display mode for footer logo ('original' | 'filtered')
 *
 * Uses INSERT IGNORE throughout so existing installations are never disrupted.
 * The legacy 'logo' and 'favicon' settings are not touched.
 */
class AddBrandingSettings extends Migration
{
    public function up(): void
    {
        $rows = [
            // key                 value       group
            ['logo_header',       '',          'branding'],
            ['logo_footer',       '',          'branding'],
            ['logo_alt',          '',          'branding'],
            ['logo_header_mode',  'original',  'branding'],
            ['logo_footer_mode',  'original',  'branding'],
        ];

        foreach ($rows as [$key, $value, $group]) {
            $this->db->query(
                "INSERT IGNORE INTO iw_settings (setting_key, setting_value, setting_group) VALUES (:k, :v, :g)",
                ['k' => $key, 'v' => $value, 'g' => $group]
            );
        }
    }

    public function down(): void
    {
        $this->db->query(
            "DELETE FROM iw_settings WHERE setting_key IN
             ('logo_header', 'logo_footer', 'logo_alt', 'logo_header_mode', 'logo_footer_mode')"
        );
    }
}
