<?php

namespace App\Classes\Modules\Milestones\ControllersLogic;

use App\Http\Resources\MilestoneResource;

use App\Classes\General\Abstracts\AbstractControllerLogic;

use App\Classes\Modules\Milestones\Services\FetchesMilestone;

use App\Classes\Modules\Milestones\Standards\Rules\CanDeleteMilestone;
use App\Classes\Modules\Milestones\Services\DeletesMilestone;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class DeleteMilestoneLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Delete Milestone',
            'message' => 'You have successfully deleted the Milestone'
        ];
    }

    /** @var CanDeleteMilestone */
    private $canDeleteMilestone;

    /** @var DeletesMilestone */
    private $deletesMilestone;

    /** @var FetchesMilestone */
    private $fetchesMiestone;


    /**
     * DeleteMilestoneLogic constructor.
     * @param CanDeleteMilestone $canDeleteMilestone
     * @param DeletesMilestone $deletesMilestone
     * @param FetchesMilestone $fetchesMiestone
     */
    public function __construct(
        CanDeleteMilestone $canDeleteMilestone,
        DeletesMilestone $deletesMilestone,
        FetchesMilestone $fetchesMiestone
    )
    {
        $this->canDeleteMilestone = $canDeleteMilestone;
        $this->deletesMilestone = $deletesMilestone;
        $this->fetchesMiestone = $fetchesMiestone;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function logic(Request $request) : JsonResponse
    {

        $query = $this->fetchesMiestone->execute(['id' => $request->route('id')]);
        $this->canDeleteMilestone->passes();
        $this->deletesMilestone->execute($query);

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

}
