<?php

namespace App\Classes\Modules\Transports\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transports\Services\ListsTransports;
use App\Classes\Modules\Transports\Standards\Rules\CanListTransports;
use App\Http\Resources\TransportResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListTransportsLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Retrieved Transports',
            'message' => 'You have successfully retrieved a list of Transports'
        ];
    }

    /** @var CanListTransports */
    private $canListTransports;

    /** @var ListsTransports */
    private $listsTransports;

    /**
     * ListTransportsLogic constructor.
     * @param CanListTransports $canListTransports
     * @param ListsTransports $listsTransports
     */
    public function __construct(CanListTransports $canListTransports, ListsTransports $listsTransports)
    {
        $this->canListTransports = $canListTransports;
        $this->listsTransports = $listsTransports;
    }


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

        $query = $this->listsTransports->execute($this->listsTransports->deserializeFilters($request->input('filters')));

        return $this->collectionResponse(TransportResource::collection($query));
    }

}
