<?php

namespace Tests\Unit\Services\Invoices;

use App\Services\Invoices\InvoiceGradeService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class InvoiceGradeServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_grade_parsing_handles_common_cases(): void
    {
        $service = new InvoiceGradeService(9);

        $this->assertTrue($service->isKindergarten('KG'));
        $this->assertSame(1, $service->gradeLevelInt('K'));
        $this->assertSame(-1, $service->gradeLevelInt('PK'));
        $this->assertSame(10, $service->gradeLevelInt('Youth'));
        $this->assertSame(5, $service->gradeLevelInt('Grade 5'));

        $info = $service->getGradeLevel('5A');
        $this->assertSame(5, $info['level']);
        $this->assertSame('A', $info['suffix']);
    }

    public function test_compare_grades_orders_numeric_then_suffix(): void
    {
        $service = new InvoiceGradeService(9);

        $this->assertSame(-1, $service->compareGrades('1', '2'));
        $this->assertSame(1, $service->compareGrades('2', '1'));
        $this->assertSame(-1, $service->compareGrades('2A', '2B'));
        $this->assertSame(0, $service->compareGrades('K', 'K'));
    }
}
