<?php

declare(strict_types=1);

namespace App\Scolarite\Domain\Model\Competency;

final class Competency
{
    private function __construct(
        public private(set) CompetencyId $id,
        public private(set) CompetencyFrameworkId $frameworkId,
        public private(set) string $code,
        public private(set) string $name,
        public private(set) ?string $description,
        public private(set) ?CompetencyId $parentId,
        public private(set) int $sortOrder,
    ) {
    }

    public static function creer(
        CompetencyFrameworkId $frameworkId,
        string $code,
        string $name,
        ?string $description,
        ?CompetencyId $parentId,
        int $sortOrder,
    ): self {
        return new self(
            id: CompetencyId::generate(),
            frameworkId: $frameworkId,
            code: $code,
            name: $name,
            description: $description,
            parentId: $parentId,
            sortOrder: $sortOrder,
        );
    }

    /**
     * @internal Pour usage Infrastructure uniquement
     */
    public static function reconstitute(
        CompetencyId $id,
        CompetencyFrameworkId $frameworkId,
        string $code,
        string $name,
        ?string $description,
        ?CompetencyId $parentId,
        int $sortOrder,
    ): self {
        return new self(
            id: $id,
            frameworkId: $frameworkId,
            code: $code,
            name: $name,
            description: $description,
            parentId: $parentId,
            sortOrder: $sortOrder,
        );
    }
}
