<?php

declare(strict_types=1);

namespace App\Tests\Unit\Scolarite\Domain\Model\Competency;

use App\Scolarite\Domain\Model\Competency\CompetencyFramework;
use App\Scolarite\Domain\Model\Competency\CompetencyFrameworkId;
use App\Shared\Domain\Tenant\TenantId;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class CompetencyFrameworkTest extends TestCase
{
    private const string TENANT_ID = '550e8400-e29b-41d4-a716-446655440001';

    #[Test]
    public function creerSetsAllProperties(): void
    {
        $tenantId = TenantId::fromString(self::TENANT_ID);
        $now = new DateTimeImmutable('2026-04-01 10:00:00');

        $framework = CompetencyFramework::creer(
            tenantId: $tenantId,
            name: 'Socle commun',
            isDefault: true,
            now: $now,
        );

        self::assertTrue($framework->tenantId->equals($tenantId));
        self::assertSame('Socle commun', $framework->name);
        self::assertTrue($framework->isDefault);
        self::assertEquals($now, $framework->createdAt);
    }

    #[Test]
    public function reconstituteRestoresAllProperties(): void
    {
        $id = CompetencyFrameworkId::generate();
        $tenantId = TenantId::fromString(self::TENANT_ID);
        $createdAt = new DateTimeImmutable('2026-04-01 10:00:00');

        $framework = CompetencyFramework::reconstitute(
            id: $id,
            tenantId: $tenantId,
            name: 'Référentiel personnalisé',
            isDefault: false,
            createdAt: $createdAt,
        );

        self::assertTrue($framework->id->equals($id));
        self::assertTrue($framework->tenantId->equals($tenantId));
        self::assertSame('Référentiel personnalisé', $framework->name);
        self::assertFalse($framework->isDefault);
        self::assertEquals($createdAt, $framework->createdAt);
    }
}
