<?php

declare(strict_types=1);

use App\Infrastructure\Db\Migrations\BaseMigration;

final class CreateIpEnrichment extends BaseMigration
{
    public function change(): void
    {
        $table = $this->table('ip_enrichment', [
            'id' => false,
            'primary_key' => ['ip_bin'],
        ]);

        $this->addIpBinaryColumn($table, 'ip_bin', ['null' => false]);
        $table
            ->addColumn('country_code', 'string', ['limit' => 2, 'null' => true])
            ->addColumn('asn', 'integer', ['null' => true, 'signed' => false])
            ->addColumn('as_org', 'string', ['limit' => 255, 'null' => true]);

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

        $table
            ->addIndex(['country_code'])
            ->addIndex(['asn'])
            ->create();
    }
}
