<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

/**
 * Runtime settings store (used by Core\Settings) and audit log.
 */
final class CreateAiSettings extends AbstractMigration
{
    public function change(): void
    {
        $this->table('ai_settings', ['id' => false, 'primary_key' => 'setting_key'])
            ->addColumn('setting_key',   'string', ['limit' => 100])
            ->addColumn('setting_value',  'text',   ['null' => true])
            ->addColumn('description',    'string', ['limit' => 255, 'null' => true])
            ->addColumn('category',       'string', ['limit' => 50,  'null' => true])
            ->addColumn('updated_at',     'datetime', ['null' => true])
            ->addColumn('updated_by',     'integer',  ['null' => true, 'signed' => false])
            ->addIndex('category')
            ->create();

        $this->table('ai_settings_log', ['id' => 'log_id', 'signed' => false])
            ->addColumn('setting_key',  'string',  ['limit' => 100])
            ->addColumn('old_value',    'text',    ['null' => true])
            ->addColumn('new_value',    'text',    ['null' => true])
            ->addColumn('changed_at',   'datetime')
            ->addColumn('changed_by',   'integer', ['null' => true, 'signed' => false])
            ->addIndex('setting_key')
            ->create();
    }
}