<?php

namespace App\Classes\Modules\Jobs\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Jobs\Processors\FetchesJobResultProcessor;
use App\Http\Resources\JobResultResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class FetchJobResultLogic extends AbstractControllerLogic
{

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

    /** @var FetchesJobResultProcessor */
    private $fetchesJobResultProcessor;

    /**
     * FetchJobResultLogic constructor.
     * @param FetchesJobResultProcessor $fetchesJobResultProcessor
     */
    public function __construct(FetchesJobResultProcessor $fetchesJobResultProcessor)
    {
        $this->fetchesJobResultProcessor = $fetchesJobResultProcessor;
    }


    /**
     * @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
    {
        $query = $this->fetchesJobResultProcessor->execute($request);

        return $this->resourceResponse(new JobResultResource($query));
    }

}
