<?php

namespace App\Jobs;

use App\Services\Business\BusinessFactory;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

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

    public $shop;
    public $businessOrderItem;
    public $num;
    public $isIncremental = true;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($shop, $businessOrderItem, $num, $isIncremental)
    {
        $this->shop = $shop;
        $this->businessOrderItem = $businessOrderItem;
        $this->num = $num;
        $this->isIncremental = $isIncremental;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if ($this->businessOrderItem) {
            BusinessFactory::init()->make($this->shop['plat_id'])->setShopWithId($this->shop['id'])->incrQuantity($this->businessOrderItem, $this->num, $this->isIncremental);
        }
    }
}
