<?php

namespace App\Listeners;

use App\Events\CreateLogisticEvent;
use App\Models\Shop;
use App\Services\Business\BusinessFactory;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class CreateLogisticListener implements ShouldQueue
{
    public $connection = 'redis';

    public $queue = 'listeners';

    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  CreateLogisticEvent  $event
     * @return void
     */
    public function handle(CreateLogisticEvent $event)
    {
        $shop = Shop::query()->findOrFail($event->shopId);
        $client = BusinessFactory::init()->make($shop['plat_id'])->setShop($shop);
        $client->createLogistic($event->orderSn, $event->waybillNo);
    }
}
