<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Contracts\Auth\MustVerifyEmail;
class User extends Authenticatable implements MustVerifyEmail { use HasFactory,Notifiable; protected $fillable=['name','email','password','status','last_login_at','mfa_enabled','mfa_verified_at']; protected $hidden=['password','remember_token']; protected function casts():array{return ['email_verified_at'=>'datetime','last_login_at'=>'datetime','mfa_verified_at'=>'datetime','mfa_enabled'=>'boolean','password'=>'hashed'];} public function roles(){return $this->belongsToMany(Role::class);} public function employee(){return $this->hasOne(Employee::class);} public function intern(){return $this->hasOne(Intern::class);} public function documents(){return $this->hasMany(WorkerDocument::class);} public function hasRole(string ...$slugs):bool{return $this->roles->contains(fn($x)=>in_array($x->slug,$slugs,true));} public function hasPermission(string $permission):bool{return $this->hasRole('founder')||$this->roles()->whereHas('permissions',fn($q)=>$q->where('slug',$permission))->exists();} public function workerType():?string{return $this->employee?'employee':($this->intern?'intern':null);} }