<?php

namespace Tests\Unit\Services\Scores;

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

class ProjectCalculatorTest extends TestCase
{
    use RefreshDatabase;

    public function test_calculate_returns_average_score(): void
    {
        DB::table('project')->insert([
            [
                'student_id' => 9,
                'school_id' => 'S1',
                'class_section_id' => 1,
                'updated_by' => 1,
                'project_index' => 1,
                'score' => 95,
                'semester' => 'Fall',
                'school_year' => '2024-2025',
            ],
            [
                'student_id' => 9,
                'school_id' => 'S1',
                'class_section_id' => 1,
                'updated_by' => 1,
                'project_index' => 2,
                'score' => 85,
                'semester' => 'Fall',
                'school_year' => '2024-2025',
            ],
            [
                'student_id' => 9,
                'school_id' => 'S1',
                'class_section_id' => 2,
                'updated_by' => 1,
                'project_index' => 3,
                'score' => 100,
                'semester' => 'Fall',
                'school_year' => '2024-2025',
            ],
        ]);

        $service = new ProjectCalculator(new Project());
        $result = $service->calculate(9, 'Fall', '2024-2025', 1);

        $this->assertSame(90.0, $result['project_avg']);
    }
}
