<?php

namespace Tests\Unit\Services\Grading;

use App\Services\Grading\GradingBelowSixtyService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class GradingBelowSixtyServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_list_rows_returns_students_below_sixty(): void
    {
        DB::table('students')->insert([
            'id' => 100,
            'parent_id' => 10,
            'firstname' => 'Kid',
            'lastname' => 'User',
            'school_id' => 1,
            'age' => 10,
            'gender' => 'M',
            'photo_consent' => 1,
            'year_of_registration' => '2025',
            'is_active' => 1,
        ]);

        DB::table('classSection')->insert([
            'id' => 1,
            'class_section_id' => 1,
            'class_section_name' => '1A',
            'class_id' => 1,
            'semester' => 'Fall',
            'school_year' => '2025-2026',
        ]);

        DB::table('semester_scores')->insert([
            'id' => 1,
            'student_id' => 100,
            'school_id' => 1,
            'class_section_id' => 1,
            'semester' => 'Fall',
            'school_year' => '2025-2026',
            'semester_score' => 55,
        ]);

        $service = new GradingBelowSixtyService();
        $rows = $service->listRows('2025-2026', 'Fall');

        $this->assertCount(1, $rows);
        $this->assertSame(100, (int) $rows[0]['student_id']);
        $this->assertSame('Open', $rows[0]['status']);
    }
}
