<?php

namespace Tests\Unit\Services\Scores;

use App\Models\AttendanceRecord;
use App\Models\CalendarEvent;
use App\Models\Configuration;
use App\Services\Scores\AttendanceCalculator;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class AttendanceCalculatorTest extends TestCase
{
    use RefreshDatabase;

    public function test_calculate_uses_configured_days(): void
    {
        DB::table('configuration')->insert([
            ['config_key' => 'total_semester1_days', 'config_value' => '10'],
        ]);

        DB::table('attendance_record')->insert([
            'class_section_id' => 1,
            'student_id' => 10,
            'school_id' => 'S1',
            'total_absence' => 2,
            'total_late' => 0,
            'total_presence' => 0,
            'total_attendance' => 0,
            'semester' => 'Fall',
            'school_year' => '2024-2025',
        ]);

        $service = new AttendanceCalculator(new AttendanceRecord(), new Configuration(), new CalendarEvent());
        $result = $service->calculate(10, 'Fall', '2024-2025');

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