<?php

namespace Ales0sa\Laradash\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\SoftDeletes;
//use Junges\ACL\Traits\UsersTrait;
use Spatie\Permission\Traits\HasRoles;
use Spatie\Permission\Models\Permission;
//use Illuminate\Support\Facades\Auth;

class User extends Authenticatable
{

    use HasRoles, Notifiable, SoftDeletes;//, UsersTrait;

    protected $guard_name = 'web';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password', 'username', 'root', 'uuid', 'image', 'last_name'
    ];

    protected $with = ['roles', 'permissions'];

    protected $appends = [
//        'roles',
        'access',
        'groups'
    ];
    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public function getRoles2Attribute(){
        return $this->getRoleNames;
    }

    public function getAccessAttribute(){
        return $this->api_token;
    }

    public function getGroupsAttribute()
    {
        return $this->roles->first();
    }

    public function orders()
    {
        return $this->hasMany(StaffAward::class, 'staff_id')->with('reason');
    }
    
    public function tokens()
    {
        
    }

    public function createToken($name)
    {
        $token = [
            'name' => $name,
            'token' => \Str::random(60),
        ];

        return $token;
    }

}
