<?php


use Illuminate\Database\Eloquent\Model as Eloquent;

class User extends Eloquent
{

    protected $table   = 'users';
    protected $guarded = ['id'];

    public function register($args)
    {
        if(User::where('email','=',$args['email']->count() > 0))
        return 1;

        $created = User::create([
            'first_name'              => $args['fires_name'],
            'last_name'               => $args['last_name'],
            'email'                   => $args['email'],
            'city'                    => $args['city'],
            'address'                 => $args['address'],
            'confirmation_fi_arrival' => 1, // no need for confirmation
        ]);

        if($created)
            return true;
        else
            return 2;
    }

    public static function checkToken($token)
    {
        if($user = User::where('token','=',$token)
                ->where('transport','=',0)
                ->count() > 0) {
            return User::where('token','=',$token)->get();
        }

        return false;
    }

    public static function updateArrivalStatus($status, $id)
    {
        $user = User::find($id);
        $user->arrival_status = $status;

        if($user->save()) {
            return true;
        }

        return false;
    }

    public static function updateTransport($transport, $id)
    {
        $user = User::find($id);
        $user->transport = $transport;

        if($user->save()) {
            return true;
        }

        return false;
    }
}