<?php

namespace App\Classes\Modules\SegmentConstants\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Segments\Services\FetchesConstant;
use App\Http\Resources\ConstantResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class FetchSegmentConstantLogic extends AbstractControllerLogic
{

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

    /** @var FetchesConstant */
    private $fetchesConstant;

    /**
     * FetchSegmentLogic constructor.
     * @param FetchesConstant $fetchesConstant
     */
    public function __construct(FetchesConstant $fetchesConstant)
    {
        $this->fetchesConstant = $fetchesConstant;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function logic(Request $request) : JsonResponse
    {
        $query = $this->fetchesConstant->execute(['id' => $request->route('id')]);

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

    }

}