<?php

namespace Lc\SovBundle\Controller\User;

use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Container\User\UserContainer;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Definition\RolesDefinition;
use Lc\SovBundle\Definition\RolesDefinitionInterface;
use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Factory\User\UserFactory;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

abstract class UserAdminController extends AbstractAdminController
{
    protected RolesDefinitionInterface $rolesDefinition;

    public function __construct(
            SessionInterface $session,
            RequestStack $request,
            EntityManager $em,
            TranslatorAdmin $translatorAdmin,
            RolesDefinitionInterface $rolesDefinition
    ) {
        $this->rolesDefinition = $rolesDefinition;
    }

    public function configureFields(string $pageName): iterable
    {

        return [
                EmailField::new('email'),
                TextField::new('lastname'),
                TextField::new('firstname'),
                ChoiceField::new('roles')
                        ->allowMultipleChoices()
                        ->autocomplete()
                        ->setChoices($this->rolesDefinition->getRolesList())
        ];
    }

    public function createEntity(string $entityFqcn)
    {
        return $this->get(UserContainer::class)->getFactory()->create();
    }
}
