<?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 Department 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
     */

    // Utilisateur qui a créé le département
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    // Mouvements de stock associés au département
    public function movementStocks()
    {
        return $this->hasMany(MovementStock::class);
    }

    // Demandes du département
    public function requests()
    {
        return $this->hasMany(Request::class);
    }

    // Équipements du département
    public function equipment()
    {
        return $this->hasMany(Equipment::class);
    }

    //Génération de la référence unique pour le département
    public static function generateReference()
    {
        return 'DEP-00' . strtoupper(Str::random(2));
    }
}