<?php

namespace App;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable //implements MustVerifyEmail
{
    use Notifiable, HasRoles;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'id',
        'name',
        'email',
        'password',
        'image',
        'provider',
        'provider_id',
        'active'
    ];

    /**
     * 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 user_data()
    {
        return $this->hasOne('App\UserData');
    }

    public function scopeActive(Builder $query)
		{
			return $query->where('active', 1);
		}

    public function getFullNameAttribute()
    {
        return implode(' ', [$this->user_data->first_name, $this->user_data->last_name]);
    }

    public function orders()
    {
        return $this->hasMany('App\Order');
    }
}
