<?php
declare(strict_types=1);

use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Migration\AbstractMigration;

/**
 * user_two_factor_recovery_codes — one-time recovery codes (Plan 007 §3).
 * Generated at enrolment, shown to the user ONCE, and stored only as a hash
 * (password_hash). `used_at` burns a code on first successful use. Renamed from
 * V1's `user_recovery_codes` for `two_factor_` prefix consistency.
 */
final class CreateUserTwoFactorRecoveryCodes extends AbstractMigration
{
    public function change(): void
    {
        $this->table('user_two_factor_recovery_codes')
            ->addColumn('user_id', AdapterInterface::PHINX_TYPE_INTEGER, [
                'signed' => false,
                'null' => false,
            ])
            ->addColumn('code_hash', AdapterInterface::PHINX_TYPE_STRING, ['limit' => 255, 'null' => false])
            ->addColumn('used_at', AdapterInterface::PHINX_TYPE_INTEGER, ['null' => true, 'default' => null])
            ->addColumn('created', AdapterInterface::PHINX_TYPE_INTEGER, ['null' => true, 'default' => null])
            ->addColumn('created_by', AdapterInterface::PHINX_TYPE_INTEGER, ['null' => true, 'default' => null])
            ->addColumn('modified', AdapterInterface::PHINX_TYPE_INTEGER, ['null' => true, 'default' => null])
            ->addColumn('modified_by', AdapterInterface::PHINX_TYPE_INTEGER, ['null' => true, 'default' => null])
            ->addIndex(['user_id'])
            ->addForeignKey('user_id', 'users', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
            ->create();
    }
}
