<?php

namespace App\Models;

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

class User extends Authenticatable implements JWTSubject
{
    use HasApiTokens, HasFactory, Notifiable;

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims()
    {
        return [];
    }

    protected $table = 'felhasznalok';

    protected $fillable = [
        'nev',
        'email',
        'felh_nev',
        'jelszo',
        'is_admin',
    ];

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

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

    public function getAuthPassword()
    {
        return $this->jelszo;
    }

    public function setJelszoAttribute($value)
    {
        $this->attributes['jelszo'] = \Illuminate\Support\Facades\Hash::make($value);
    }
}