<?php

declare(strict_types=1);

use App\Infrastructure\Db\Migrations\BaseMigration;

final class CreateReporters extends BaseMigration
{
    public function change(): void
    {
        $table = $this->table('reporters');
        $table
            ->addColumn('name', 'string', ['limit' => 128, 'null' => false])
            ->addColumn('description', 'text', ['null' => true])
            ->addColumn('trust_weight', 'decimal', ['precision' => 5, 'scale' => 2, 'null' => false, 'default' => '1.00'])
            ->addColumn('is_active', 'boolean', ['null' => false, 'default' => true])
            ->addColumn('created_by_user_id', 'integer', ['null' => true, 'signed' => false]);

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

        $table
            ->addIndex(['name'], ['unique' => true, 'name' => 'uniq_reporters_name'])
            ->addIndex(['created_by_user_id'])
            ->addForeignKey(
                'created_by_user_id',
                'users',
                'id',
                ['delete' => 'SET_NULL', 'update' => 'NO_ACTION', 'constraint' => 'fk_reporters_created_by']
            )
            ->create();
    }
}
