<?php

namespace App\Classes\Modules\Transactions\ControllersLogic;

use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transactions\Services\ListsGroups;
use App\Http\Resources\GroupResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListGroupsLogic extends AbstractControllerLogic
{
    /**
     * ListTransactionsLogic constructor.
     * @param ListsGroups $listsGroups
     */
    public function __construct(ListsGroups $listsGroups)
    {
        $this->listsGroups = $listsGroups;
    }

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

    /** @var ListsGroups */
    private $listsGroups;

    public function logic(Request $request) : JsonResponse
    {
        $query = $this->listsGroups->execute($this->listsGroups->deserializeFilters($request->input('filters')));

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

}
