<?php

namespace Tests\Unit\Services\ClassPrep;

use App\Services\ClassPrep\ClassRosterService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class ClassRosterServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_list_students_by_class(): void
    {
        $this->seedRosterData();

        $service = new ClassRosterService();
        $students = $service->listStudentsByClass(101, '2025-2026');

        $this->assertCount(1, $students);
        $this->assertSame('1-A', $students[0]['registration_grade']);
    }

    private function seedRosterData(): void
    {
        DB::table('configuration')->insert([
            ['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
        ]);

        DB::table('classes')->insert([
            'id' => 1,
            'class_name' => 'Class 1',
            'schedule' => 'Sun',
            'capacity' => 20,
            'semester' => 'Fall',
            'school_year' => '2025-2026',
        ]);

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

        DB::table('students')->insert([
            'school_id' => 'S-1',
            'firstname' => 'Student',
            'lastname' => 'One',
            'age' => 8,
            'gender' => 'Male',
            'photo_consent' => 1,
            'parent_id' => 1,
            'year_of_registration' => '2025',
            'school_year' => '2025-2026',
            'semester' => 'Fall',
            'is_active' => 1,
            'is_new' => 0,
        ]);

        DB::table('student_class')->insert([
            'student_id' => 1,
            'class_section_id' => 101,
            'semester' => 'Fall',
            'school_year' => '2025-2026',
        ]);
    }
}
