<?php

namespace App\Classes\Modules\Schedules\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Schedules\Services\DeletesSchedule;
use App\Classes\Modules\Schedules\Services\FetchesSchedule;
use App\Classes\Modules\Schedules\Standards\Rules\CanDeleteSchedule;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class DeleteScheduleLogic extends AbstractControllerLogic
{
    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Deleted Schedule',
            'message' => 'You have successfully deleted a Schedule'
        ];
    }


    /** @var CanDeleteSchedule */
    private $canDeleteSchedule;

    /** @var DeletesSchedule */
    private $deletesSchedule;

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

    /**
     * DeleteScheduleControllersLogic constructor.
     * @param CanDeleteSchedule $canDeleteSchedule
     * @param DeletesSchedule $deletesSchedule
     * @param FetchesSchedule $fetchesSchedule
     */
    public function __construct(CanDeleteSchedule $canDeleteSchedule, DeletesSchedule $deletesSchedule, FetchesSchedule $fetchesSchedule)
    {
        $this->canDeleteSchedule = $canDeleteSchedule;
        $this->deletesSchedule = $deletesSchedule;
        $this->fetchesSchedule = $fetchesSchedule;
    }

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

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

        $this->deletesSchedule->execute($query);

        return $this->response([]);
    }

}
