<?php

namespace App\Models;

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

/**
 * @method bool hasRole(string $role)
 */
class User extends Authenticatable
{
    use HasFactory, Notifiable;

    protected $table = 'users';
    protected $primaryKey = 'id_user';
    public $timestamps = true;

    protected $fillable = [
        'name',
        'email',
        'password',
        'role',
        'reset_password', // Tambahkan kolom ini agar bisa diisi secara massal
    ];

    protected $hidden = [
        'password',
        'remember_token',
        'reset_password', // Sembunyikan agar tidak terlihat ketika objek dikonversi ke JSON
    ];

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

    // Method untuk memeriksa peran pengguna
    public function hasRole($role)
    {
        return $this->role === $role;
    }

    public function bookings()
{
    return $this->hasMany(Booking::class, 'id_user', 'id_user');
}
}
