<?php

namespace App\Classes\Modules\Segments\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Segments\Services\DeletesSegment;
use App\Classes\Modules\Segments\Services\FetchesSegment;
use App\Classes\Modules\Segments\Standards\Rules\CanDeleteSegment;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

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


    /** @var CanDeleteSegment */
    private $canDeleteSegment;

    /** @var DeletesSegment */
    private $deletesSegment;

    /** @var FetchesSegment */
    private $fetchesSegment;

    /**
     * DeleteSegmentLogic constructor.
     * @param CanDeleteSegment $canDeleteSegment
     * @param DeletesSegment $deletesSegment
     * @param FetchesSegment $fetchesSegment
     */
    public function __construct(CanDeleteSegment $canDeleteSegment, DeletesSegment $deletesSegment, FetchesSegment $fetchesSegment)
    {
        $this->canDeleteSegment = $canDeleteSegment;
        $this->deletesSegment = $deletesSegment;
        $this->fetchesSegment = $fetchesSegment;
    }


    /**
     * @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
    {

        $this->canDeleteSegment->passes();

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

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

        return $this->response([]);

    }

}