<?php

namespace App\Jobs;

use App\Models\Notification;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class CreateDelayNotificationPhone implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    protected $userId;

    public function __construct($userId)
    {
        //
        $this->userId = $userId;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
        $userId = $this->userId;
        $user = User::find($userId);
        if($user)
        {
            if(!$user->status_phone)
            {
                Notification::create( [
                    'to_user'   => $userId,
                    'title'     => 'Thông báo từ itro.vn',
                    'user_id'   => $userId,
                    'content'   => 'Hãy bảo vệ tài khoản và dữ liệu của bạn bằng việc xác thực số điện thoại ngay bây giờ'
                ] );
            }

            if(empty($user->email))
            {
                Notification::create( [
                    'to_user'   => $userId,
                    'title'     => 'Thông báo từ itro.vn',
                    'user_id'   => $userId,
                    'content'   => 'Hãy cập nhật email vào tài khoản của bạn. Khi bạn quên mật khẩu thì có thể dùng email để lấy lại mật khẩu'
                ] );
            }
        }
    }
}
