<?php

namespace Tests\Unit\Services\Scores;

use App\Services\Scores\ScoreTermService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class ScoreTermServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_semester_and_school_year_fallback_to_configuration(): void
    {
        DB::table('configuration')->insert([
            ['config_key' => 'semester', 'config_value' => 'Fall'],
            ['config_key' => 'school_year', 'config_value' => '2025-2026'],
        ]);

        $service = new ScoreTermService();

        $this->assertSame('Fall', $service->semesterLabel(null));
        $this->assertSame('2025-2026', $service->schoolYear(null));
    }

    public function test_normalize_and_variants(): void
    {
        $service = new ScoreTermService();

        $this->assertSame('fall', $service->normalizeSemester('Semester 1'));
        $this->assertSame('spring', $service->normalizeSemester('2nd Semester'));

        $variants = $service->semesterVariants('Fall');
        $this->assertContains('First Semester', $variants);
        $this->assertContains('Semester 1', $variants);
    }
}
