<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class DoctorTest extends Model
{
    protected $fillable = [
        'doctor_id','name','name_en','category',
        'instructions','is_active','usage_count','sort_order',
    ];

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

    public function doctor()
    {
        return $this->belongsTo(Doctor::class);
    }

    public function scopePopular($query, $limit = 20)
    {
        return $query->where('is_active', true)
                     ->orderByDesc('usage_count')
                     ->orderBy('sort_order')
                     ->limit($limit);
    }

    public function incrementUsage(): void
    {
        $this->increment('usage_count');
    }
}
