<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;
    protected $fillable = ['name', 'email', 'password', 'divisi_id', 'role', 'phone'];
    protected $hidden = ['password', 'remember_token'];
    public function divisi()
    {
        return $this->belongsTo(Divisi::class);
    }
    public function borrowRequests()
    {
        return $this->hasMany(BorrowRequest::class);
    }
    public function isRole($role)
    {
        return $this->role === $role;
    }
    public function itemRequests()
    {
        return $this->hasMany(\App\Models\ItemRequest::class);
    }

    public function approvedItemRequests()
    {
        return $this->hasMany(\App\Models\ItemRequest::class, 'approved_by');
    }
}
