<?php

namespace App\Jobs;

use App\Good;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

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

    protected $id;

    public $timeout = 300;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($gid)
    {
        $this->id = $gid;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {

        if (!Good::where('id', $this->id)->whereColumn('number', 'trace_count')->exists()) {
            \Artisan::call("generate:key", ['gid' => $this->id]);
        }
    }
}
