<?php

namespace App\Domain\Training\Models;

use App\Domain\Shared\Traits\BelongsToAcademy;
use App\Domain\Shared\Traits\HasUuid;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class EvaluationCriterion extends Model
{
    use BelongsToAcademy, HasUuid, SoftDeletes;

    protected $table = 'evaluation_criteria';

    protected $fillable = [
        'academy_id',
        'name_ar',
        'name',
        'description_ar',
        'category',
        'max_score',
        'sort_order',
        'is_active',
        'metadata',
    ];

    protected $casts = [
        'max_score' => 'integer',
        'sort_order' => 'integer',
        'is_active' => 'boolean',
        'metadata' => 'array',
    ];

    public function scores(): HasMany
    {
        return $this->hasMany(EvaluationScore::class, 'criterion_id');
    }

    public function scopeActive(Builder $query): Builder
    {
        return $query->where('is_active', true);
    }

    public function scopeByCategory(Builder $query, string $category): Builder
    {
        return $query->where('category', $category);
    }
}
