<?php

namespace App\Jobs;

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

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

    /** @var Waybill|\stdClass */
    protected $waybill;
    /**
     * Create a new job instance.
     *
     * @param Waybill $waybill
     *
     * @return void
     */
    public function __construct(Waybill $waybill)
    {
        $this->waybill = $waybill;
    }

    /**
     * Execute the job.
     *
     * @return void
     *
     * @throws
     */
    public function handle()
    {
        $order = Order::query()->where("code",$this->waybill->wms_bill_number)->first();
        if ($order)$this->waybill->update(["order_id"=>$order->id]);
        else throw new \Exception("order does not exist");
    }
}
