<?php

namespace App\Classes\Modules\ServiceTypes\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\ServiceTypes\Services\FetchesServiceType;
use App\Classes\Modules\ServiceTypes\Standards\Rules\CanFetchServiceType;
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
use App\Http\Resources\ServiceTypeResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class FetchServiceTypeLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Retrieved Service Type',
            'message' => 'You have successfully retrieved a Service Type'
        ];
    }

    /** @var CanFetchServiceType */
    private $canFetchServiceType;

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

    /**
     * FetchServiceTypeLogic constructor.
     * @param CanFetchServiceType $canFetchServiceType
     * @param FetchesServiceType $fetchesServiceType
     */
    public function __construct(CanFetchServiceType $canFetchServiceType, FetchesServiceType $fetchesServiceType)
    {
        $this->canFetchServiceType = $canFetchServiceType;
        $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->canFetchServiceType->passes();

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

        return $this->resourceResponse(new ServiceTypeResource($query));

    }

}