<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

use Spatie\Permission\Traits\HasRoles;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Deligoez\LaravelModelHashId\Traits\HasHashId;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Request extends Model
{
    /** @use HasFactory<\Database\Factories\UserFactory> */
    use HasFactory, Notifiable, HasHashId, HasRoles, SoftDeletes;

    /**
     * The attributes that are mass assignable.
     *
     * @var list<string>
     */
    protected $guarded = [];

    /**
     * Relations
     */

    // Département qui a fait la demande
    public function department()
    {
        return $this->belongsTo(Department::class);
    }

    // Utilisateur associé à la demande
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    // Utilisateur qui a créé la demande
    public function createdBy()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    // Utilisateur qui a approuvé la demande
    public function approvedBy()
    {
        return $this->belongsTo(User::class, 'approved_by');
    }

    // Utilisateur qui a rejeté la demande
    public function rejectedBy()
    {
        return $this->belongsTo(User::class, 'rejected_by');
    }

    // Détails de la demande
    public function requestDetails()
    {
        return $this->hasMany(RequestDetail::class);
    }
}
