<?php

namespace App\Classes\Modules\ServiceTypes\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\ServiceTypes\Services\DeletesServiceType;
use App\Classes\Modules\ServiceTypes\Services\FetchesServiceType;
use App\Classes\Modules\ServiceTypes\Standards\Rules\CanDeleteServiceType;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

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


    /** @var CanDeleteServiceType */
    private $canDeleteServiceType;

    /** @var DeletesServiceType */
    private $deletesServiceType;

    /** @var FetchesServiceType */
        private $fetchesServiceType;

    /**
     * DeleteServiceTypeLogic constructor.
     * @param CanDeleteServiceType $canDeleteServiceType
     * @param DeletesServiceType $deletesServiceType
     * @param FetchesServiceType $fetchesServiceType
     */
    public function __construct(CanDeleteServiceType $canDeleteServiceType, DeletesServiceType $deletesServiceType, FetchesServiceType $fetchesServiceType)
    {
        $this->canDeleteServiceType = $canDeleteServiceType;
        $this->deletesServiceType = $deletesServiceType;
        $this->fetchesServiceType = $fetchesServiceType;
    }


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

        $this->canDeleteServiceType->passes();

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

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

        return $this->response([]);

    }

}