<?php

declare(strict_types=1);

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

use App\Shared\Infrastructure\Tenant\TenantConfig;
use App\Shared\Infrastructure\Tenant\TenantId;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

#[CoversClass(TenantConfig::class)]
final class TenantConfigTest extends TestCase
{
    #[Test]
    public function itCanBeCreatedWithRequiredProperties(): void
    {
        $tenantId = TenantId::fromString('a1b2c3d4-e5f6-7890-abcd-ef1234567890');
        $subdomain = 'ecole-alpha';
        $databaseUrl = 'postgresql://user:pass@localhost:5432/classeo_alpha';

        $config = new TenantConfig(
            tenantId: $tenantId,
            subdomain: $subdomain,
            databaseUrl: $databaseUrl,
        );

        self::assertTrue($tenantId->equals($config->tenantId));
        self::assertSame($subdomain, $config->subdomain);
        self::assertSame($databaseUrl, $config->databaseUrl);
    }

    #[Test]
    public function itIsImmutable(): void
    {
        $config = new TenantConfig(
            tenantId: TenantId::fromString('a1b2c3d4-e5f6-7890-abcd-ef1234567890'),
            subdomain: 'ecole-alpha',
            databaseUrl: 'postgresql://user:pass@localhost:5432/classeo_alpha',
        );

        $reflection = new ReflectionClass($config);

        self::assertTrue($reflection->isReadonly());
    }
}
