<?php

declare(strict_types=1);

namespace App\Tests\Unit\Logging;

use App\Logging\LogIdentifier;
use PHPUnit\Framework\TestCase;

final class LogIdentifierTest extends TestCase
{
    public function testFingerprintIsStableAcrossCalls(): void
    {
        $a = LogIdentifier::fingerprint('admin');
        $b = LogIdentifier::fingerprint('admin');
        self::assertSame($a, $b);
    }

    public function testFingerprintDistinguishesDifferentInputs(): void
    {
        self::assertNotSame(
            LogIdentifier::fingerprint('admin'),
            LogIdentifier::fingerprint('Admin'),
        );
        self::assertNotSame(
            LogIdentifier::fingerprint('10.0.0.1'),
            LogIdentifier::fingerprint('10.0.0.2'),
        );
    }

    public function testFingerprintDoesNotContainRawValue(): void
    {
        $fp = LogIdentifier::fingerprint('hunter2-this-was-typed-as-username');
        self::assertStringNotContainsString('hunter2', $fp);
    }

    public function testFingerprintLengthIsBounded(): void
    {
        // 12 hex chars: short enough for log readability, long enough that
        // collisions are negligible across a deployment's logs.
        self::assertSame(12, strlen(LogIdentifier::fingerprint('admin')));
        self::assertSame(12, strlen(LogIdentifier::fingerprint(str_repeat('x', 4096))));
    }

    public function testEmptyInputReturnsSentinel(): void
    {
        self::assertSame('empty', LogIdentifier::fingerprint(''));
    }
}
