<?php

namespace App\Classes\Modules\Remarks\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Remarks\Services\FetchesRemark;
use App\Classes\Modules\Remarks\Standards\Rules\CanFetchRemark;
use App\Http\Resources\RemarkResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class FetchRemarkLogic extends AbstractControllerLogic
{

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

    /** @var CanFetchRemark */
    private $canFetchRemark;

    /** @var FetchesRemark */
    private $fetchesRemark;

    /**
     * FetchRemarkControllersLogic constructor.
     * @param CanFetchRemark $canFetchRemark
     * @param FetchesRemark $fetchesRemark
     */
    public function __construct(CanFetchRemark $canFetchRemark, FetchesRemark $fetchesRemark)
    {
        $this->canFetchRemark = $canFetchRemark;
        $this->fetchesRemark = $fetchesRemark;
    }


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

        $query = $this->fetchesRemark->execute(['id' => $request->route('id')]);

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

}
