<?php namespace App\Jobs\Shopify;

use App\Services\Shopify\ProductsService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

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

    /**
     * Id for the product to sync
     *
     * @var int
     */
    protected $productGid;
    public $backoff = [3, 30, 100];

    /**
     * Create a new job instance.
     *
     * @param stdClass $data
     *
     * @return void
     */
    public function __construct(string $productGid)
    {
        $this->productGid = $productGid;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(ProductsService $service)
    {
        Log::info('Archive Shopify Product - ' . $this->productGid);
        if ($service->archiveProduct($this->productGid)) {
            Log::info('Archive Shopify Product - success');
        } else {
            Log::warning('Error while archiving Shopify Product');
        }
    }
}
