<?php

declare(strict_types=1);

namespace App\Scolarite\Domain\Model\Evaluation;

use App\Scolarite\Domain\Exception\BaremeInvalideException;

use function round;

final readonly class GradeScale
{
    public function __construct(
        public int $maxValue,
    ) {
        if ($maxValue < 1 || $maxValue > 100) {
            throw BaremeInvalideException::avecValeur($maxValue);
        }
    }

    public function convertTo20(float $grade): float
    {
        return round(($grade / $this->maxValue) * 20, 2);
    }

    public function equals(self $other): bool
    {
        return $this->maxValue === $other->maxValue;
    }
}
