<?php

namespace App\Classes\Modules\Schedules\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Schedules\Services\ListsSchedules;
use App\Classes\Modules\Schedules\Standards\Rules\CanListSchedules;
use App\Http\Resources\ScheduleResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListSchedulesLogic extends AbstractControllerLogic
{

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

    /** @var CanListSchedules */
    private $canListSchedules;

    /** @var ListsSchedules */
    private $listsSchedules;

    /**
     * ListSchedulesLogic constructor.
     * @param CanListSchedules $canListSchedules
     * @param ListsSchedules $listsSchedules
     */
    public function __construct(CanListSchedules $canListSchedules, ListsSchedules $listsSchedules)
    {
        $this->canListSchedules = $canListSchedules;
        $this->listsSchedules = $listsSchedules;
    }


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

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

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

}
