<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laratrust\Traits\LaratrustUserTrait;
use App\Notifications\VerifyEmail;
use App\Notifications\ResetPassword as ResetPasswordNotification;

class User extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;

    /**
     * Send the email verification notification.
     *
     * @return void
     */
    public function sendEmailVerificationNotification()
    {
        $this->notify(new VerifyEmail);
    }

    public function sendPasswordResetNotification($token)
    {
        $this->notify(new ResetPasswordNotification($token));
    }

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'last_login',
        'name',
        'last_name',
        'email',
        'password',
        'phone',
        'landing_emails',
        'status'
    ];

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

    public function parent()
    {
        return $this->belongsTo('App\Models\User', 'parent_id');
    }

    public function role()
    {
        return $this->belongsTo('App\Models\Role', 'role_id');
    }

    public function leads()
    {
        return $this->hasMany('App\Models\Lead', 'added_by');
    }

    public function calling_databases()
    {
        return $this->hasMany('App\Models\CallingDatabase', 'added_by');
    }

    public function contacts()
    {
        return $this->hasMany('App\Models\Contact', 'added_by');
    }

    public function appointments()
    {
        return $this->hasMany('App\Models\Appointment', 'added_by');
    }

    public function listings()
    {
        return $this->hasMany('App\Models\Listing', 'added_by')->with('project', 'purpose');
    }

    public function simple_listings()
    {
        return $this->hasMany('App\Models\Listing', 'added_by');
    }

    public function main_listings()
    {
        return $this->hasMany('App\Models\Listing', 'added_by')->where('type', 2)->with('project', 'purpose');
    }
}
