<?php

namespace App\Classes\Modules\Transports\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transports\Services\DeletesTransport;
use App\Classes\Modules\Transports\Services\FetchesTransport;
use App\Classes\Modules\Transports\Standards\Rules\CanDeleteTransport;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class DeleteTransportLogic extends AbstractControllerLogic
{
    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Deleted Transport',
            'message' => 'You have successfully deleted a Transport'
        ];
    }


    /** @var CanDeleteTransport */
    private $canDeleteTransport;

    /** @var DeletesTransport */
    private $deletesTransport;

    /** @var FetchesTransport */
    private $fetchesTransport;

    /**
     * DeleteTransportControllersLogic constructor.
     * @param CanDeleteTransport $canDeleteTransport
     * @param DeletesTransport $deletesTransport
     * @param FetchesTransport $fetchesTransport
     */
    public function __construct(CanDeleteTransport $canDeleteTransport, DeletesTransport $deletesTransport, FetchesTransport $fetchesTransport)
    {
        $this->canDeleteTransport = $canDeleteTransport;
        $this->deletesTransport = $deletesTransport;
        $this->fetchesTransport = $fetchesTransport;
    }


    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ErrorException
     */
    public function logic(Request $request) : JsonResponse
    {
        $this->canDeleteTransport->passes();

        $query = $this->fetchesTransport->execute(['id' => $request->route('id')]);

        $this->deletesTransport->execute($query);

        return $this->response([]);
    }

}
