<?php


namespace App\Classes\Modules\Orders\ControllersLogic;

use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Orders\Services\ListsOrders;
use App\Classes\Modules\Orders\Standards\Rules\CanListOrders;
use App\Http\Resources\OrderResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

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

    /** @var CanListOrders */
    private $canListOrders;

    /** @var ListsOrders */
    private $listsOrders;

    /**
     * ListOrdersLogic constructor.
     * @param CanListOrders $canListOrders
     * @param ListsOrders $listsOrders
     */
    public function __construct(CanListOrders $canListOrders, ListsOrders $listsOrders)
    {
        $this->canListOrders = $canListOrders;
        $this->listsOrders = $listsOrders;
    }

    public function logic(Request $request) : JsonResponse
    {
        $this->canListOrders->passes();

        $query = $this->listsOrders->execute(array_merge($this->listsOrders->deserializeFilters($request->input('filters')), ['with_parcels' => true]));

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

    }



}
