<?php
namespace Incoviba\Controller\Admin;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Alias\View;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Repository;

class Users
{
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
                             Repository\User $userRepository): ResponseInterface
    {
        $users = [];
        try {
            $users = $userRepository->fetchAll('name');
        } catch (EmptyResult) {}
        return $view->render($response, 'admin.users', compact('users'));
    }
}
