<?php

namespace App\Classes\Modules\Companies\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\ListsCompanyModules;
use App\Classes\Modules\Companies\Standards\Rules\CanListCompanies;
use App\Http\Resources\CompanyModuleResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListCompanyModulesLogic extends AbstractControllerLogic
{

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

    /** @var CanListCompanies */
    private $canListCompanies;

    /** @var ListsCompanyModules */
    private $listsCompanyModules;

    /**
     * ListCompaniesControllersLogic constructor.
     * @param CanListCompanies $canListCompanies
     * @param ListsCompanyModules $listsCompanyModules
     */
    public function __construct(CanListCompanies $canListCompanies, ListsCompanyModules $listsCompanyModules)
    {
        $this->canListCompanies = $canListCompanies;
        $this->listsCompanyModules = $listsCompanyModules;
    }


    /**
     * @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->canListCompanies->passes();

        $query = $this->listsCompanyModules->execute($this->listsCompanyModules->deserializeFilters($request->input('filters')));
        return $this->collectionResponse(CompanyModuleResource::collection($query));

    }

}