<?php

namespace App\Classes\Modules\Companies\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Standards\Rules\CanFetchCompany;
use App\Http\Resources\CompanyResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class FetchCompanyLogic extends AbstractControllerLogic
{

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

    /** @var CanFetchCompany */
    private $canFetchCompany;

    /** @var FetchesCompany */
    private $fetchesCompany;

    /**
     * FetchCompanyControllersLogic constructor.
     * @param CanFetchCompany $canFetchCompany
     * @param FetchesCompany $fetchesCompany
     */
    public function __construct(CanFetchCompany $canFetchCompany, FetchesCompany $fetchesCompany)
    {
        $this->canFetchCompany = $canFetchCompany;
        $this->fetchesCompany = $fetchesCompany;
    }


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

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

        return $this->resourceResponse(new CompanyResource($query));

    }

}