<?php

namespace Tests\Unit\Services\Scores;

use App\Models\Homework;
use App\Services\Scores\HomeworkCalculator;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class HomeworkCalculatorTest extends TestCase
{
    use RefreshDatabase;

    public function test_calculate_returns_average_score(): void
    {
        DB::table('homework')->insert([
            [
                'student_id' => 5,
                'school_id' => 'S1',
                'class_section_id' => 1,
                'updated_by' => 1,
                'homework_index' => 1,
                'score' => 80,
                'semester' => 'Fall',
                'school_year' => '2024-2025',
            ],
            [
                'student_id' => 5,
                'school_id' => 'S1',
                'class_section_id' => 1,
                'updated_by' => 1,
                'homework_index' => 2,
                'score' => 90,
                'semester' => 'Fall',
                'school_year' => '2024-2025',
            ],
            [
                'student_id' => 5,
                'school_id' => 'S1',
                'class_section_id' => 1,
                'updated_by' => 1,
                'homework_index' => 3,
                'score' => null,
                'semester' => 'Fall',
                'school_year' => '2024-2025',
            ],
        ]);

        $service = new HomeworkCalculator(new Homework());
        $result = $service->calculate(5, 'Fall', '2024-2025', 1);

        $this->assertSame(85.0, $result['homework_avg']);
    }
}
