<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Enseignant extends Model
{
    protected $connection = 'tenant';
    protected $table = 'enseignant';
    protected $primaryKey = 'matricule';
    public $timestamps = false;

    protected $fillable = [
        'nom',
        'prenom',
        'sexe',
        'lieu_nais',
        'date_nais',
        'cheminPhoto',
        'phone',
        'email',
        'enfonction',
        'idGrade',
        'nationalite',
        'adresse'
    ];

    protected $hidden = [
        'password',
        'login',
        'token',
        'sign'
    ];

    /**
     * Get the full name of the teacher
     */
    public function getNomCompletAttribute()
    {
        return $this->nom . ' ' . $this->prenom;
    }

    /**
     * Get the courses taught by this teacher
     */
    public function ecus()
    {
        return $this->hasMany(Ecu::class, 'matricule', 'matricule');
    }

    /**
     * Get the grade of the teacher
     */
    public function grade()
    {
        return $this->belongsTo(Grade::class, 'idGrade', 'idGrade');
    }

    /**
     * Scope to filter teachers currently in function
     */
    public function scopeEnFonction($query)
    {
        return $query->where('enfonction', 'YES');
    }
}
