<?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 Illuminate\Support\Facades\DB;

class Users extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;
    protected $table='users';
    protected $primaryKey = 'maNguoiDung';
    public $timestamps = false;
    protected $fillable = [
        'Ten',
        'TenDangNhap',
        'MatKhau',
        'VaiTro',
        'Email',
    ];

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

    public function getAuthIdentifierName()
    {
        return 'maNguoiDung';
    }

    public function getAuthIdentifier()
    {
        return $this->{$this->getAuthIdentifierName()};
    }
    public static function getPossibleEnumValues($name){
        $instance = new static;
        $query = 'SHOW COLUMNS FROM ' . $instance->getTable() . ' WHERE Field = "' . $name . '"';
        $type = DB::select($query)[0]->Type;
        preg_match('/^enum\((.*)\)$/', $type, $matches);
        $enum = [];
        if (!empty($matches[1])) {
            $enum = array_map(function ($value) {
                return trim($value, "'");
            }, explode(',', $matches[1]));
        }
        return $enum;
    }
    public static function hasPermission(){

        return true;
    }
    public function routes(){
        return ['admin','quanlythongtin'];
    }
}
