<?php

declare(strict_types=1);

namespace App\Tests\Unit\Shared\Infrastructure\Tenant;

use App\Shared\Infrastructure\Tenant\TenantId;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;

#[CoversClass(TenantId::class)]
final class TenantIdTest extends TestCase
{
    #[Test]
    public function itCanBeGeneratedWithRandomUuid(): void
    {
        $tenantId = TenantId::generate();

        self::assertTrue(Uuid::isValid((string) $tenantId));
    }

    #[Test]
    public function itCanBeCreatedFromString(): void
    {
        $uuid = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';

        $tenantId = TenantId::fromString($uuid);

        self::assertSame($uuid, (string) $tenantId);
    }

    #[Test]
    public function twoTenantIdsWithSameValueAreEqual(): void
    {
        $uuid = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';

        $tenantId1 = TenantId::fromString($uuid);
        $tenantId2 = TenantId::fromString($uuid);

        self::assertTrue($tenantId1->equals($tenantId2));
    }

    #[Test]
    public function twoTenantIdsWithDifferentValuesAreNotEqual(): void
    {
        $tenantId1 = TenantId::fromString('a1b2c3d4-e5f6-7890-abcd-ef1234567890');
        $tenantId2 = TenantId::fromString('b2c3d4e5-f6a7-8901-bcde-f12345678901');

        self::assertFalse($tenantId1->equals($tenantId2));
    }

    #[Test]
    public function itCanBeConvertedToString(): void
    {
        $uuid = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';
        $tenantId = TenantId::fromString($uuid);

        self::assertSame($uuid, (string) $tenantId);
    }
}
