<?php

declare(strict_types=1);

namespace App\Scolarite\Domain\Model\Grade;

use function abs;

use App\Scolarite\Domain\Exception\ValeurNoteInvalideException;

final readonly class GradeValue
{
    public function __construct(
        public float $value,
    ) {
        if ($value < 0) {
            throw ValeurNoteInvalideException::valeurNegative($value);
        }
    }

    public function equals(self $other): bool
    {
        return abs($this->value - $other->value) < 0.001;
    }
}
