<?php

namespace App\Classes\Modules\HelpMenu\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\HelpMenu\Standards\Rules\CanFetchHelpMenuQuestion;
use App\Classes\Modules\HelpMenu\Processors\FetchFirstQuestionQAProcessor;
use App\Http\Resources\HelpMenuQuestionResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class FetchQuestionQALogic extends AbstractControllerLogic
{

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

    /** @var CanFetchHelpMenuQuestion */
    private $canFetchHelpMenuQuestion;

    /** @var FetchFirstQuestionQAProcessor */
    private $fetchFirstQuestionQAProcessor;

    /**
     * FetchQuestionQALogic constructor.
     * @param CanFetchHelpMenuQuestion $canFetchHelpMenuQuestion
     * @param FetchFirstQuestionQAProcessor $fetchFirstQuestionQAProcessor
     */
    public function __construct(CanFetchHelpMenuQuestion $canFetchHelpMenuQuestion, FetchFirstQuestionQAProcessor $fetchFirstQuestionQAProcessor)
    {
        $this->canFetchHelpMenuQuestion = $canFetchHelpMenuQuestion;
        $this->fetchFirstQuestionQAProcessor = $fetchFirstQuestionQAProcessor;
    }


    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ErrorException
     */
    public function logic(Request $request) : JsonResponse
    {
        $this->canFetchHelpMenuQuestion->passes();

        $userId = Auth::user()->id;

        $query = $this->fetchFirstQuestionQAProcessor->execute($request);

        return $this->resourceResponse(new HelpMenuQuestionResource($query, $userId));
    }

}
