<?php

/**
 * Migration 050 – Add configurable admin slug setting.
 *
 * Allows the admin panel URL prefix to be changed from /admin to a custom path
 * (e.g. /mein-backend, /cms-control) for additional security.
 */

use App\Database\Migration;

class AddAdminSlugSetting extends Migration
{
    public function up(): void
    {
        $exists = $this->db->fetch(
            "SELECT id FROM iw_settings WHERE setting_key = 'admin_slug' LIMIT 1"
        );

        if (!$exists) {
            $this->db->insert('iw_settings', [
                'setting_key'   => 'admin_slug',
                'setting_value' => 'admin',
                'setting_group' => 'system',
            ]);
        }
    }

    public function down(): void
    {
        $this->db->query(
            "DELETE FROM iw_settings WHERE setting_key = 'admin_slug'"
        );
    }
}
