<?php

namespace App\Classes\Modules\ServiceTypes\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\ServiceTypes\Services\ListsServiceTypes;
use App\Classes\Modules\ServiceTypes\Standards\Rules\CanListServiceTypes;
use App\Http\Resources\ServiceTypeResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListServiceTypesLogic extends AbstractControllerLogic
{

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

    /** @var CanListServiceTypes */
    private $canListServiceTypes;

    /** @var ListsServiceTypes */
    private $listsServiceTypes;

    /**
     * ListServiceTypesControllerLogic constructor.
     * @param CanListServiceTypes $canListServiceTypes
     * @param ListsServiceTypes $listsServiceTypes
     */
    public function __construct(CanListServiceTypes $canListServiceTypes, ListsServiceTypes $listsServiceTypes)
    {
        $this->canListServiceTypes = $canListServiceTypes;
        $this->listsServiceTypes = $listsServiceTypes;
    }


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

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

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

    }

}