<?php

/**
 * Migration 043 – Add HTTP cache settings
 *
 * Enables configurable Cache-Control, ETag and Last-Modified headers
 * for frontend pages to improve performance and Core Web Vitals.
 */

use App\Database\Migration;

class AddHttpCacheSettings extends Migration
{
    public function up(): void
    {
        $settings = [
            ['setting_key' => 'http_cache_enabled', 'setting_value' => '0', 'setting_group' => 'performance'],
            ['setting_key' => 'http_cache_ttl',     'setting_value' => '3600', 'setting_group' => 'performance'],
        ];

        foreach ($settings as $s) {
            $exists = $this->db->fetch(
                "SELECT 1 FROM iw_settings WHERE setting_key = :key",
                ['key' => $s['setting_key']]
            );
            if (!$exists) {
                $this->db->insert('iw_settings', $s);
            }
        }
    }

    public function down(): void
    {
        $this->db->query("DELETE FROM iw_settings WHERE setting_key IN ('http_cache_enabled', 'http_cache_ttl')");
    }
}
