<?php

namespace App\Command;

use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

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

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $commands = [
            [
                'name' => 'Encender',
                'enabled' => true,
                'readOnly' => true,
            ],
            [
                'name' => 'Apagar',
                'enabled' => true,
                'readOnly' => true,
            ],
            [
                'name' => 'Restaurar Imagen',
                'enabled' => true,
                'readOnly' => true,
            ],
            [
                'name' => 'Crear Imagen',
                'enabled' => true,
                'readOnly' => true,
            ],
            [
                'name' => 'Reiniciar',
                'enabled' => true,
                'readOnly' => true,
            ],
            [
                'name' => 'Inventario Hardware',
                'enabled' => true,
                'readOnly' => true,
            ],
            [
                'name' => 'Inventario Software',
                'enabled' => true,
                'readOnly' => true,
            ],
            [
                'name' => 'Ejecutar Script',
                'enabled' => true,
                'readOnly' => true,
            ],
            [
                'name' => 'Iniciar Sesion',
                'enabled' => true,
                'readOnly' => true,
            ],
            [
                'name' => 'Particionar y Formatear',
                'enabled' => true,
                'readOnly' => true,
            ],
            [
                'name' => 'Eliminar Imagen Cache',
                'enabled' => true,
                'readOnly' => true,
            ],
        ];

        foreach ($commands as $command) {
            $entity = new \App\Entity\Command();
            $entity->setName($command['name']);

            $entity->setScript('');
            $entity->setEnabled($command['enabled']);
            $entity->setReadOnly($command['readOnly']);

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

        $this->entityManager->flush();

        return Command::SUCCESS;
    }
}