<?php

namespace Tests\Unit;

use App\Support\PairingCode;
use PHPUnit\Framework\TestCase;

class PairingCodeTest extends TestCase
{
    public function test_generates_xxx_xxx_format(): void
    {
        for ($i = 0; $i < 50; $i++) {
            $code = PairingCode::generate();
            $this->assertMatchesRegularExpression('/^\d{3}-\d{3}$/', $code);
        }
    }

    public function test_generates_varied_codes(): void
    {
        $codes = [];
        for ($i = 0; $i < 50; $i++) {
            $codes[] = PairingCode::generate();
        }
        $this->assertGreaterThan(40, count(array_unique($codes)));
    }

    public function test_normalize_strips_non_digits_and_reformats(): void
    {
        $this->assertSame('123-456', PairingCode::normalize('123-456'));
        $this->assertSame('123-456', PairingCode::normalize('123456'));
        $this->assertSame('123-456', PairingCode::normalize(' 123 456 '));
        $this->assertSame('123-456', PairingCode::normalize('123 - 456'));
    }

    public function test_normalize_returns_null_for_bad_input(): void
    {
        $this->assertNull(PairingCode::normalize('12345'));
        $this->assertNull(PairingCode::normalize('abc-def'));
        $this->assertNull(PairingCode::normalize(''));
    }
}
