<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Evaluacion extends Model
{
    protected $table = 'evaluaciones';
    protected $guarded = [];

    protected $casts = [
        'anonima'      => 'boolean',
        'fecha_inicio' => 'date',
        'fecha_fin'    => 'date',
    ];

    public function tipo(): BelongsTo
    {
        return $this->belongsTo(EvaluacionTipo::class, 'evaluacion_tipo_id');
    }

    public function preguntas(): HasMany
    {
        return $this->hasMany(Pregunta::class)->orderBy('orden');
    }

    public function planteles(): BelongsToMany
    {
        return $this->belongsToMany(Plantel::class, 'evaluacion_plantel');
    }

    public function niveles(): BelongsToMany
    {
        return $this->belongsToMany(Nivel::class, 'evaluacion_nivel');
    }

    public function submissions(): HasMany
    {
        return $this->hasMany(EvaluacionSubmission::class);
    }
}
