<?php

/**
 * Migration 045 – Add page cache settings
 *
 * File-based full-page cache toggle and TTL.
 */

use App\Database\Migration;

class AddPageCacheSettings extends Migration
{
    public function up(): void
    {
        $settings = [
            ['page_cache_enabled', '0', 'performance'],
            ['page_cache_ttl',     '3600', 'performance'],
        ];

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

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