<?php

namespace KupShop\UserManagerBundle\Controller;

use KupShop\KupShopBundle\Routing\TranslatedRoute;
use KupShop\UserManagerBundle\View\UserManagerView;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class UserManagerController extends AbstractController
{
    /**
     * @TranslatedRoute("/#account#/#user-manager#/")
     */
    public function usersListAction(Request $request, UserManagerView $view): Response
    {
        if ($userId = (int) $request->get('userId')) {
            // odeslat email na nastaveni hesla
            if ($request->get('setPassword')) {
                $view->sendSetPasswordEmail($userId);
            }

            // povolit / blokovat uzivatele
            if ($figure = $request->get('setFigure')) {
                $view->updateUserFigure($userId, $figure);
            }

            return new RedirectResponse(
                path('kupshop_usermanager_usermanager_userslist')
            );
        }

        return $view->getResponse();
    }
}
