<?php

namespace Tests\Unit\Services\Scores;

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

class QuizCalculatorTest extends TestCase
{
    use RefreshDatabase;

    public function test_calculate_returns_average_score(): void
    {
        DB::table('quiz')->insert([
            [
                'student_id' => 7,
                'school_id' => 'S1',
                'class_section_id' => 2,
                'updated_by' => 1,
                'quiz_index' => 1,
                'score' => 70,
                'semester' => 'Fall',
                'school_year' => '2024-2025',
            ],
            [
                'student_id' => 7,
                'school_id' => 'S1',
                'class_section_id' => 2,
                'updated_by' => 1,
                'quiz_index' => 2,
                'score' => 90,
                'semester' => 'Fall',
                'school_year' => '2024-2025',
            ],
            [
                'student_id' => 7,
                'school_id' => 'S1',
                'class_section_id' => 3,
                'updated_by' => 1,
                'quiz_index' => 3,
                'score' => 100,
                'semester' => 'Fall',
                'school_year' => '2024-2025',
            ],
            [
                'student_id' => 7,
                'school_id' => 'S1',
                'class_section_id' => 2,
                'updated_by' => 1,
                'quiz_index' => 4,
                'score' => null,
                'semester' => 'Fall',
                'school_year' => '2024-2025',
            ],
        ]);

        $service = new QuizCalculator();
        $result = $service->calculate(7, 'Fall', '2024-2025', 2);

        $this->assertSame(80.0, $result['quiz_avg']);
    }
}
