<?php

namespace App\Models;

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

class User extends Authenticatable
{
    use HasFactory, Notifiable;

    /**
     * Database table
     */
    protected $table = 'users';

    /**
     * Primary key
     */
    protected $primaryKey = 'user_id';

    /**
     * Primary key is integer
     */
    protected $keyType = 'int';

    /**
     * Primary key is auto incrementing
     */
    public $incrementing = true;

    /**
     * Mass assignable fields
     */
    protected $fillable = [
        'user_name',
        'user_email',
        'password',
        'role_id',
        'is_active',
    ];

    /**
     * Hidden fields
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * Attribute casting
     */
    protected function casts(): array
    {
        return [
            'is_active' => 'boolean',
            'password' => 'hashed',
        ];
    }

    /**
     * Email used for authentication
     */
   public function getAuthIdentifierName()
{
    return 'user_id';
}

public $timestamps = false;

public function role()
{
    return $this->belongsTo(
        UserRole::class,
        'role_id',
        'role_id'
    );
}
public function receiver()
{
    return $this->belongsTo(
        User::class,
        'received_by',
        'user_id'
    );
}

}