<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

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

/**
 * Class User
 *
 * @property int $id
 * @property string $name
 * @property string $username
 * @property string $password
 * @property int $role
 * @property int|null $wilayah_id
 * @property int|null $sektor_id
 * @property string|null $remember_token
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 *
 * @package App\Models
 */
class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;

    protected $fillable = [
        'name',
        'username',
        'password',
        'role',
        'wilayah_id',
        'sektor_id',
    ];

    protected $hidden = [
        'password',
        'remember_token',
    ];

    protected $casts = [
        'role' => 'integer',
        'wilayah_id' => 'integer',
        'sektor_id' => 'integer',
    ];

    public function isAdmin()
    {
        return $this->role === 1;
    }

    public function isKetuaWilayah()
    {
        return $this->role === 2;
    }

    public function isKetuaSektor()
    {
        return $this->role === 3;
    }
}
