<?php

namespace App\Classes\Modules\Segments\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 FetchConstantLogic extends AbstractControllerLogic
{

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


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

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


    /**
     * @param Request $request
     * @return JsonResponse
     */
    public function logic(Request $request) : JsonResponse
    {

        $constant = $this->fetchesConstant->execute(['segment_id' => $request->route('id'), 'reference' => $request->route('reference')]);

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

    }

}