<?php

namespace Tests\Unit\Services\Attendance;

use App\Services\Attendance\AttendanceCommentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class AttendanceCommentServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_comment_from_score_uses_template_and_name(): void
    {
        DB::table('attendance_comment_template')->insert([
            [
                'min_score' => 90,
                'max_score' => 100,
                'template_text' => '{name} attendance is excellent.',
                'is_active' => 1,
            ],
            [
                'min_score' => 0,
                'max_score' => 89,
                'template_text' => 'needs improvement in attendance.',
                'is_active' => 1,
            ],
        ]);

        $service = new AttendanceCommentService();
        $comment = $service->commentFromScore(95, 'James');

        $this->assertSame("James' attendance is excellent.", $comment);
    }

    public function test_comment_from_score_falls_back_to_this_student(): void
    {
        DB::table('attendance_comment_template')->insert([
            'min_score' => 0,
            'max_score' => 100,
            'template_text' => 'needs improvement in attendance.',
            'is_active' => 1,
        ]);

        $service = new AttendanceCommentService();
        $comment = $service->commentFromScore(70);

        $this->assertSame("This student's needs improvement in attendance.", $comment);
    }
}
