<?php

namespace App\Jobs;

use App\OrderPackage;
use App\Services\OrderService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class WeightUpdateInstantBill implements ShouldQueue
{
    use SerializesModels;

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

    /**
     * Execute the job.
     *
     * @param OrderService $service
     *
     * @return void
     */
    public function handle(OrderService $service)
    {
        if (!$this->package->weight)return;
        $this->package->loadMissing("order");
        if (!$this->package->order)return;
        $service->reviseLogisticFee($this->package->order);
    }
}
