<?php
/**
 * Created by PhpStorm.
 * User: mhmj
 * Date: 18/06/2019
 * Time: 10:11 AM
 */

namespace App\Classes\Modules\Orders\Services;


use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
use App\Classes\ValueObjects\Constants\HttpStatus;
use App\Models\Schedule;
use Illuminate\Http\JsonResponse;

class DeletesOrderSchedule
{
    /** @var  Schedule */
    private $repository;

    /**
     * DeletesOrderSchedule constructor.
     * @param Schedule $repository
     */
    public function __construct(Schedule $repository)
    {
        $this->repository = $repository;
    }

    public function execute(String $scheduleId){

        try{
            $schedule = $this->repository->findOrfail($scheduleId);
            $schedule -> delete();
            return new JsonResponse([],HttpStatus::OK);

        }catch(\Exception $exception){
            throw new InternalServerErrorException("Failed to delete schedule because {$exception->getMessage()}");
        }

    }

}