<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Activite extends Model
{
    protected $primaryKey = 'ID_Instance';
    protected $table = 'activites';
    public $incrementing = true;
    public $timestamps = false;

    protected $fillable = [
        'DateDebut',
        'DateFin',
        'ID_Utilisateur_Hote',
        'ID_Ressource',
    ];

    protected $casts = [
        'DateDebut' => 'datetime',
        'DateFin' => 'datetime',
    ];

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

    public function ressource()
    {
        return $this->belongsTo(Ressource::class, 'ID_Ressource', 'ID_Ressource');
    }

    public function messages()
    {
        return $this->hasMany(ActiviteMessage::class, 'ID_Instance', 'ID_Instance');
    }

    public function participants()
    {
        return $this->belongsToMany(Utilisateur::class, 'activite_participants', 'ID_Instance', 'ID_Utilisateur_Participant', 'ID_Instance', 'ID_Utilisateur');
    }
}
