<?php

namespace App\Classes\Modules\Schedules\ControllersLogic;


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

class FetchScheduleLogic extends AbstractControllerLogic
{

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

    /** @var CanFetchSchedule */
    private $canFetchSchedule;

    /** @var FetchesSchedule */
    private $fetchesSchedule;

    /**
     * FetchScheduleControllersLogic constructor.
     * @param CanFetchSchedule $canFetchSchedule
     * @param FetchesSchedule $fetchesSchedule
     */
    public function __construct(CanFetchSchedule $canFetchSchedule, FetchesSchedule $fetchesSchedule)
    {
        $this->canFetchSchedule = $canFetchSchedule;
        $this->fetchesSchedule = $fetchesSchedule;
    }


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

        $query = $this->fetchesSchedule->execute(['id' => $request->route('id')]);

        return $this->resourceResponse(new ScheduleResource($query));
    }

}
