<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Ressource extends Model
{
    protected $primaryKey = 'ID_Ressource';
    protected $table = 'ressources';
    public $incrementing = true;

    protected $fillable = [
        'Titre',
        'Contenu',
        'URL',
        'Visibilite',
        'Statut',
        'ID_Type_Ressource',
        'ID_Moderateur_Validation',
        'ID_Utilisateur_Createur',
    ];

    protected $casts = [
        'DateCreation' => 'datetime',
    ];

    public function type()
    {
        return $this->belongsTo(TypeRessource::class, 'ID_Type_Ressource', 'ID_Type_Ressource');
    }

    public function categories()
    {
        return $this->belongsToMany(Categorie::class, 'ressource_categories', 'ID_Ressource', 'ID_Categorie', 'ID_Ressource', 'ID_Categorie');
    }

    public function createur()
    {
        return $this->belongsTo(Utilisateur::class, 'ID_Utilisateur_Createur', 'ID_Utilisateur');
    }

    public function moderateur()
    {
        return $this->belongsTo(Utilisateur::class, 'ID_Moderateur_Validation', 'ID_Utilisateur');
    }

    public function commentaires()
    {
        return $this->hasMany(Commentaire::class, 'ID_Ressource', 'ID_Ressource');
    }

    public function activites()
    {
        return $this->hasMany(Activite::class, 'ID_Ressource', 'ID_Ressource');
    }

    public function progressions()
    {
        return $this->hasMany(Utilisateur_Progression::class, 'ID_Ressource', 'ID_Ressource');
    }
}