<?php

namespace App\Models;

use App\Models\Plantel;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Nivel extends Model
{
    protected $guarded = [];

    public $timestamps = false;

    public function nivelPlantel() : BelongsToMany
    {
        return $this->belongsToMany(Plantel::class)->withPivot('plantel_id');
    }

    public function nivelPlane() : BelongsToMany
    {
        return $this->belongsToMany(Plane::class);
    }

    public function existe($plantelId = null)
    {
        if (!$plantelId) {
            return false;
        }

        return $this->nivelPlantel()
            ->wherePivot('plantel_id', $plantelId)
            ->exists();
    }

    public function documentosRequeridos()
    {
        return $this->belongsToMany(
            DocumentoTipo::class,
            'nivel_documento',
            'nivel_id',
            'documento_tipo_id'
        );
    }

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