<?php

namespace App\Classes\Modules\HelpMenu\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\HelpMenu\Services\ListsHelpMenuUserAnswerSelected;
use App\Classes\Modules\HelpMenu\Standards\Rules\CanListHelpMenuQuestions;
use App\Http\Resources\HelpMenuQuestionsAnswersResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListQuestionsAnswersQALogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Retrieved Questions Answers',
            'message' => 'You have successfully retrieved a list of questions and answers'
        ];
    }

    /** @var CanListHelpMenuQuestions */
    private $canListHelpMenuQuestions;

    /** @var ListsHelpMenuUserAnswerSelected */
    private $listsHelpMenuUserAnswerSelected;

    /**
     * ListQuestionsAnswersQALogic constructor.
     * @param CanListHelpMenuQuestions $canListHelpMenuQuestions
     * @param ListsHelpMenuUserAnswerSelected $listsHelpMenuUserAnswerSelected
     */
    public function __construct(CanListHelpMenuQuestions $canListHelpMenuQuestions, ListsHelpMenuUserAnswerSelected $listsHelpMenuUserAnswerSelected)
    {
        $this->canListHelpMenuQuestions = $canListHelpMenuQuestions;
        $this->listsHelpMenuUserAnswerSelected = $listsHelpMenuUserAnswerSelected;
    }


    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function logic(Request $request) : JsonResponse
    {
        $this->canListHelpMenuQuestions->passes();

        $query = $this->listsHelpMenuUserAnswerSelected->execute($this->listsHelpMenuUserAnswerSelected->deserializeFilters($request->input('filters')));

        return $this->collectionResponse(HelpMenuQuestionsAnswersResource::collection($query));
    }

}
