<?php


namespace App\Classes\Modules\Bookings\ControllersLogic;

use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Bookings\Services\ListsBookings;
use App\Classes\Modules\Bookings\Standards\Rules\CanListBookings;
use App\Http\Resources\BookingResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

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

    /** @var CanListBookings */
    private $canListBookings;

    /** @var ListsBookings */
    private $listsBookings;

    /**
     * ListBookingsLogic constructor.
     * @param CanListBookings $canListBookings
     * @param ListsBookings $listsBookings
     */
    public function __construct(CanListBookings $canListBookings, ListsBookings $listsBookings)
    {
        $this->canListBookings = $canListBookings;
        $this->listsBookings = $listsBookings;
    }

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

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

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

    }



}
