<?php

namespace App\Models;

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

class Etablissement extends Model
{
    use HasFactory;
    protected $fillable = ['id','libellear', 'libellefr','cycle_id','code','latitude','longitude', 'etat', 'commune_id', 'date_creation', 'directeur', 'localisation', 'contact', 'email', 'photo'];

    public function commune(): BelongsTo
{ 
    return $this->belongsTo(Commune::class); 
}
public function cycle(): BelongsTo
{ 
    return $this->belongsTo(Cycle::class); 
}
public function etabAxes(): HasMany 
{ 
    return $this->hasMany(EtabAxe::class); 
}
public function infrastructures(): HasMany 
{ 
    return $this->hasMany(Infrastructure::class); 
}
public function structurePedagogiques(): HasMany
{
    return $this->hasMany(StructurePedagogique::class);
}
public function etabProfs(): HasMany 
{ 
    return $this->hasMany(EtabProf::class);
}

public function professeurs()
{
    return $this->belongsToMany(
        Professeur::class,
        'etab_profs',
        'etablissement_id',
        'professeur_id'
    )
    ->withPivot(['date_affectation'])
    ->withTimestamps();
}
}
