<?php

namespace Tests\Unit;

use App\Models\AttendanceCommentTemplate;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Tests\TestCase;

class AttendanceCommentTemplateModelTest extends TestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        Schema::dropIfExists('attendance_comment_template');

        Schema::create('attendance_comment_template', function (Blueprint $table) {
            $table->id();
            $table->decimal('min_score', 5, 2);
            $table->decimal('max_score', 5, 2);
            $table->text('template_text');
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });
    }

    public function test_get_active_templates_filters_and_orders(): void
    {
        AttendanceCommentTemplate::create([
            'min_score' => 0,
            'max_score' => 60,
            'template_text' => 'Needs improvement.',
            'is_active' => 1,
        ]);

        AttendanceCommentTemplate::create([
            'min_score' => 61,
            'max_score' => 80,
            'template_text' => 'Good progress.',
            'is_active' => 0,
        ]);

        AttendanceCommentTemplate::create([
            'min_score' => 81,
            'max_score' => 100,
            'template_text' => 'Excellent work.',
            'is_active' => 1,
        ]);

        $model = new AttendanceCommentTemplate();
        $results = $model->getActiveTemplates();

        $this->assertCount(2, $results);
        $this->assertSame(81, $results[0]['min_score']);
        $this->assertSame(0, $results[1]['min_score']);
    }
}
