<?php

declare(strict_types=1);

namespace App\Tests\Unit\Enrichment;

use App\Infrastructure\Enrichment\IpinfoRecordAdapter;
use PHPUnit\Framework\TestCase;

final class IpinfoRecordAdapterTest extends TestCase
{
    public function testCountryFlat(): void
    {
        $adapter = new IpinfoRecordAdapter();
        self::assertSame('GB', $adapter->extractCountryCode(['country_code' => 'GB']));
        self::assertSame('GB', $adapter->extractCountryCode(['country_code' => 'gb']));
        self::assertNull($adapter->extractCountryCode([]));
        self::assertNull($adapter->extractCountryCode(['country_code' => '']));
    }

    public function testAsnStripsAsPrefix(): void
    {
        $adapter = new IpinfoRecordAdapter();
        self::assertSame(13335, $adapter->extractAsn(['asn' => 'AS13335']));
        self::assertSame(13335, $adapter->extractAsn(['asn' => 'as13335']));
        self::assertSame(13335, $adapter->extractAsn(['asn' => '13335']));
        self::assertNull($adapter->extractAsn([]));
        self::assertNull($adapter->extractAsn(['asn' => 'NOTANUMBER']));
    }

    public function testAsName(): void
    {
        $adapter = new IpinfoRecordAdapter();
        self::assertSame('Cloudflare', $adapter->extractAsOrg(['as_name' => 'Cloudflare']));
        self::assertNull($adapter->extractAsOrg([]));
    }
}
