<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class Admin extends Authenticatable
{
    use Notifiable;

    protected $guard = 'admin';

    protected $fillable = [
        'full_name',
        'email',
        'password_hash',
        'avatar',
        'role',
        'permissions',
        'two_factor_enabled',
        'two_factor_secret',
        'status',
        'last_login',
    ];

    protected $hidden = [
        'password_hash',
        'two_factor_secret',
    ];

    protected $casts = [
        'permissions' => 'array',
        'last_login' => 'datetime',
        'two_factor_enabled' => 'boolean',
    ];

    public function getAuthPasswordName()
    {
        return 'password_hash';
    }

    // Allow using 'password' attribute to set password_hash automatically
    public function setPasswordAttribute($value)
    {
        $this->attributes['password_hash'] = bcrypt($value);
    }
}
