<?php

namespace App\Classes\Modules\PackingLists\ControllersLogic\Containers;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\Containers\ListsContainers;
use App\Classes\Modules\PackingLists\Standards\Rules\Containers\CanListContainers;
use App\Http\Resources\ContainerResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListContainersLogic extends AbstractControllerLogic
{

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

    /** @var CanListContainers */
    private $canListContainers;

    /** @var ListsContainers */
    private $listsContainers;

    /**
     * ListContainersLogic constructor.
     * @param CanListContainers $canListContainers
     * @param ListsContainers $listsContainers
     */
    public function __construct(CanListContainers $canListContainers, ListsContainers $listsContainers)
    {
        $this->canListContainers = $canListContainers;
        $this->listsContainers = $listsContainers;
    }


    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function logic(Request $request) : JsonResponse
    {
        $this->canListContainers->passes();

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

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

    }

}
