<?php

declare(strict_types=1);

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

use App\Scolarite\Domain\Exception\BaremeInvalideException;
use App\Scolarite\Domain\Model\Evaluation\GradeScale;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class GradeScaleTest extends TestCase
{
    #[Test]
    public function acceptsValidValues(): void
    {
        self::assertSame(1, (new GradeScale(1))->maxValue);
        self::assertSame(10, (new GradeScale(10))->maxValue);
        self::assertSame(20, (new GradeScale(20))->maxValue);
        self::assertSame(100, (new GradeScale(100))->maxValue);
    }

    #[Test]
    public function rejectsZero(): void
    {
        $this->expectException(BaremeInvalideException::class);

        new GradeScale(0);
    }

    #[Test]
    public function rejectsNegative(): void
    {
        $this->expectException(BaremeInvalideException::class);

        new GradeScale(-1);
    }

    #[Test]
    public function rejectsAbove100(): void
    {
        $this->expectException(BaremeInvalideException::class);

        new GradeScale(101);
    }

    #[Test]
    public function convertTo20ConvertsCorrectly(): void
    {
        $scale10 = new GradeScale(10);
        self::assertSame(14.0, $scale10->convertTo20(7));

        $scale20 = new GradeScale(20);
        self::assertSame(15.0, $scale20->convertTo20(15));

        $scale100 = new GradeScale(100);
        self::assertSame(17.0, $scale100->convertTo20(85));
    }

    #[Test]
    public function equalsComparesMaxValue(): void
    {
        $a = new GradeScale(20);
        $b = new GradeScale(20);
        $c = new GradeScale(10);

        self::assertTrue($a->equals($b));
        self::assertFalse($a->equals($c));
    }
}
