<?php

declare(strict_types=1);

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

use App\Scolarite\Domain\Model\Competency\Competency;
use App\Scolarite\Domain\Model\Competency\CompetencyFrameworkId;
use App\Scolarite\Domain\Model\Competency\CompetencyId;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class CompetencyTest extends TestCase
{
    #[Test]
    public function creerSetsAllProperties(): void
    {
        $frameworkId = CompetencyFrameworkId::generate();

        $competency = Competency::creer(
            frameworkId: $frameworkId,
            code: 'D1.1',
            name: 'Comprendre, s\'exprimer en utilisant la langue française',
            description: 'Domaine 1 - Langages',
            parentId: null,
            sortOrder: 1,
        );

        self::assertTrue($competency->frameworkId->equals($frameworkId));
        self::assertSame('D1.1', $competency->code);
        self::assertSame('Comprendre, s\'exprimer en utilisant la langue française', $competency->name);
        self::assertSame('Domaine 1 - Langages', $competency->description);
        self::assertNull($competency->parentId);
        self::assertSame(1, $competency->sortOrder);
    }

    #[Test]
    public function creerWithParentId(): void
    {
        $frameworkId = CompetencyFrameworkId::generate();
        $parentId = CompetencyId::generate();

        $competency = Competency::creer(
            frameworkId: $frameworkId,
            code: 'D1.1.1',
            name: 'Lire',
            description: null,
            parentId: $parentId,
            sortOrder: 1,
        );

        self::assertNotNull($competency->parentId);
        self::assertTrue($competency->parentId->equals($parentId));
        self::assertNull($competency->description);
    }

    #[Test]
    public function reconstituteRestoresAllProperties(): void
    {
        $id = CompetencyId::generate();
        $frameworkId = CompetencyFrameworkId::generate();
        $parentId = CompetencyId::generate();

        $competency = Competency::reconstitute(
            id: $id,
            frameworkId: $frameworkId,
            code: 'D2',
            name: 'Méthodes et outils pour apprendre',
            description: 'Domaine 2',
            parentId: $parentId,
            sortOrder: 2,
        );

        self::assertTrue($competency->id->equals($id));
        self::assertTrue($competency->frameworkId->equals($frameworkId));
        self::assertSame('D2', $competency->code);
        self::assertSame('Méthodes et outils pour apprendre', $competency->name);
        self::assertSame('Domaine 2', $competency->description);
        self::assertNotNull($competency->parentId);
        self::assertTrue($competency->parentId->equals($parentId));
        self::assertSame(2, $competency->sortOrder);
    }
}
