<?php

namespace App\Jobs;

use App\Services\LogisticSFService;
use App\Services\LogService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

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

    public $logistic_number;

    /**
     * @var LogisticSFService $logisticSFService
     */
    public $logisticSFService;
    public $orderPackageReceivedSyncService;

    /**
     * LogisticSFSync constructor.
     * @param $logistic_number
     */
    public function __construct($logistic_number)
    {
        $this->logistic_number = $logistic_number;
    }


    /**
     * Execute the job.
     *
     * @return void
     * @throws \Exception
     */
    public function handle()
    {
        ini_set('max_execution_time', 60);
        LogService::log(LogisticSFSync::class, "{$this->logistic_number}-JOB-SF", '');
        $this->logisticSFService = app('LogisticSFService');
        $formedData = $this->logisticSFService->get([$this->logistic_number]);
        $this->orderPackageReceivedSyncService = app('OrderPackageReceivedSyncService');
        $this->orderPackageReceivedSyncService->update($formedData);
    }
}
