<?php

declare(strict_types=1);

use App\Infrastructure\Db\Migrations\BaseMigration;

/**
 * Runtime-mutable feature flags. SPEC §M12.5 settings page is otherwise
 * read-only of env config; a small key/value table here lets admins
 * toggle feature flags (e.g. audit emission for high-volume public
 * endpoints) without restarting the api container.
 *
 * Seeds the two audit-emission flags as enabled. Defaults at the
 * application layer mirror these so a missing row is treated as enabled.
 */
final class CreateAppSettings extends BaseMigration
{
    public function change(): void
    {
        $table = $this->table('app_settings', ['id' => false, 'primary_key' => ['key']]);
        $table
            ->addColumn('key', 'string', ['limit' => 64, 'null' => false])
            ->addColumn('value', 'text', ['null' => true]);

        $this->addTimestampColumn($table, 'updated_at');

        $table->create();

        $this->table('app_settings')->insert([
            ['key' => 'audit_report_received_enabled', 'value' => '1'],
            ['key' => 'audit_blocklist_request_enabled', 'value' => '1'],
        ])->saveData();
    }
}
