<?php

namespace App\Command;

use App\Entity\UserGroup;
use App\Model\UserGroupPermissions;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class LoadDefaultUserGroupsCommand extends Command
{
    public function __construct(
        private readonly EntityManagerInterface $entityManager,
    )
    {
        parent::__construct('app:load-default-user-groups');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $userGroups = [
            [
                'name' => 'Super Admin',
                'permissions' => [UserGroupPermissions::ROLE_SUPER_ADMIN],
                'enabled' => true
            ],
            [
                'name' => 'Administrador de aulas',
                'permissions' => [UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN],
                'enabled' => true
            ],
            [
                'name' => 'Operador de aulas',
                'permissions' => [UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_OPERATOR],
                'enabled' => true
            ],
            [
                'name' => 'Usuario básico de aulas',
                'permissions' => [UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_MINIMAL],
                'enabled' => true
            ],
        ];

        foreach ($userGroups as $userGroup) {
            $entity = new UserGroup();
            $entity->setName($userGroup['name']);
            $entity->setPermissions($userGroup['permissions']);
            $entity->setEnabled($userGroup['enabled']);

            $this->entityManager->persist($entity);
        }

        $this->entityManager->flush();

        return Command::SUCCESS;
    }
}