<?php

declare(strict_types=1);

namespace App\Tests\Unit\Administration\Application\Service;

use App\Administration\Application\Service\InvitationCodeGenerator;
use App\Administration\Domain\Model\Invitation\InvitationCode;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

use function strlen;

final class InvitationCodeGeneratorTest extends TestCase
{
    private InvitationCodeGenerator $generator;

    protected function setUp(): void
    {
        $this->generator = new InvitationCodeGenerator();
    }

    #[Test]
    public function generateReturnsInvitationCode(): void
    {
        $code = $this->generator->generate();

        self::assertInstanceOf(InvitationCode::class, $code);
    }

    #[Test]
    public function generateReturns32CharacterHexCode(): void
    {
        $code = $this->generator->generate();

        self::assertSame(32, strlen($code->value));
        self::assertMatchesRegularExpression('/^[a-f0-9]{32}$/', $code->value);
    }

    #[Test]
    public function generateProducesUniqueCodesEachTime(): void
    {
        $code1 = $this->generator->generate();
        $code2 = $this->generator->generate();

        self::assertFalse($code1->equals($code2));
    }
}
