<?php

namespace Tests\Unit\Services\Scores;

use App\Services\Scores\ScorePredictorDataService;
use App\Services\Scores\ScorePredictorRiskService;
use App\Services\Scores\ScorePredictorService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class ScorePredictorServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_report_builds_predictions(): void
    {
        DB::table('configuration')->insert([
            ['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
            ['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
            ['id' => 3, 'config_key' => 'trophy_score', 'config_value' => '94'],
            ['id' => 4, 'config_key' => 'pass_score', 'config_value' => '60'],
        ]);

        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('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('student_class')->insert([
            'id' => 1,
            'student_id' => 100,
            'class_section_id' => 1,
            'school_year' => '2025-2026',
            'semester' => 'Fall',
            'is_event_only' => 0,
        ]);

        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' => 92,
        ]);

        $service = new ScorePredictorService(
            new ScorePredictorDataService(),
            new ScorePredictorRiskService()
        );

        $result = $service->report('2025-2026', 1);

        $this->assertSame('2025-2026', $result['school_year']);
        $this->assertCount(1, $result['students']);
        $this->assertSame(100, $result['students'][0]['student_id']);
    }
}
