<?php

declare(strict_types=1);

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

use App\Scolarite\Domain\Model\Competency\CustomCompetencyLevel;
use App\Scolarite\Domain\Model\Competency\CustomCompetencyLevelId;
use App\Shared\Domain\Tenant\TenantId;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

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

    #[Test]
    public function creerSetsAllProperties(): void
    {
        $tenantId = TenantId::fromString(self::TENANT_ID);

        $level = CustomCompetencyLevel::creer(
            tenantId: $tenantId,
            code: 'excellent',
            name: 'Excellent',
            color: '#9b59b6',
            sortOrder: 5,
        );

        self::assertTrue($level->tenantId->equals($tenantId));
        self::assertSame('excellent', $level->code);
        self::assertSame('Excellent', $level->name);
        self::assertSame('#9b59b6', $level->color);
        self::assertSame(5, $level->sortOrder);
    }

    #[Test]
    public function creerAllowsNullColor(): void
    {
        $level = CustomCompetencyLevel::creer(
            tenantId: TenantId::fromString(self::TENANT_ID),
            code: 'basic',
            name: 'Basique',
            color: null,
            sortOrder: 1,
        );

        self::assertNull($level->color);
    }

    #[Test]
    public function reconstituteRestoresAllProperties(): void
    {
        $id = CustomCompetencyLevelId::generate();
        $tenantId = TenantId::fromString(self::TENANT_ID);

        $level = CustomCompetencyLevel::reconstitute(
            id: $id,
            tenantId: $tenantId,
            code: 'progressing',
            name: 'En progression',
            color: '#f1c40f',
            sortOrder: 2,
        );

        self::assertTrue($level->id->equals($id));
        self::assertTrue($level->tenantId->equals($tenantId));
        self::assertSame('progressing', $level->code);
        self::assertSame('En progression', $level->name);
        self::assertSame('#f1c40f', $level->color);
        self::assertSame(2, $level->sortOrder);
    }
}
