<?php

namespace App\Models;

use App\Models\BaseModel;

class AttendanceCommentTemplate extends BaseModel
{
    protected $table = 'attendance_comment_template';

    // CI: useTimestamps = false
    public $timestamps = true;

    protected $fillable = [
        'min_score',
        'max_score',
        'template_text',
        'is_active',
        'created_at',
        'updated_at',
    ];

    protected $casts = [
        'min_score' => 'integer',
        'max_score' => 'integer',
        'is_active' => 'boolean',
    ];

    /**
     * Equivalent of CI getActiveTemplates():
     * is_active=1, order by min_score DESC
     */
    public static function getActiveTemplates()
    {
        return static::query()
            ->where('is_active', 1)
            ->orderByDesc('min_score')
            ->get();
    }

    // Optional: nice query scope version
    public function scopeActive($q)
    {
        return $q->where('is_active', 1);
    }
}