<?php

declare(strict_types=1);

namespace App\Tests\Unit\Administration\Domain\Model\Invitation;

use App\Administration\Domain\Exception\InvitationCodeInvalideException;
use App\Administration\Domain\Model\Invitation\InvitationCode;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class InvitationCodeTest extends TestCase
{
    #[Test]
    public function constructWithValidCodeCreatesInstance(): void
    {
        $code = new InvitationCode('a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4');

        self::assertSame('a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4', $code->value);
    }

    #[Test]
    public function constructWithEmptyStringThrowsException(): void
    {
        $this->expectException(InvitationCodeInvalideException::class);

        new InvitationCode('');
    }

    #[Test]
    public function constructWithTooShortCodeThrowsException(): void
    {
        $this->expectException(InvitationCodeInvalideException::class);

        new InvitationCode('abc123');
    }

    #[Test]
    public function constructWithTooLongCodeThrowsException(): void
    {
        $this->expectException(InvitationCodeInvalideException::class);

        new InvitationCode('a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4extra');
    }

    #[Test]
    public function equalsReturnsTrueForSameValue(): void
    {
        $code1 = new InvitationCode('a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4');
        $code2 = new InvitationCode('a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4');

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

    #[Test]
    public function equalsReturnsFalseForDifferentValue(): void
    {
        $code1 = new InvitationCode('a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4');
        $code2 = new InvitationCode('11111111111111111111111111111111');

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

    #[Test]
    public function toStringReturnsValue(): void
    {
        $code = new InvitationCode('a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4');

        self::assertSame('a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4', (string) $code);
    }
}
