<?php

namespace App\Command;

use App\Bundle\Crypt\AES;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ContainerInterface;


class AesCommand extends Command
{
    private $container;

    public function __construct(ContainerInterface $container)
    {
        parent::__construct();
        $this->container = $container;
    }

    protected static $defaultName = 'app:aes';
    protected static $defaultDescription = 'Add a short description for your command';

    protected function configure(): void
    {
        $this
            ->setDescription(self::$defaultDescription)
            ->addArgument('phone', InputArgument::OPTIONAL, 'variant update table')
            ->addOption('decode', null, InputOption::VALUE_OPTIONAL, 'Option description')
        ;
    }

    //  php bin/console app:aes
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $entityManager = $this->container->get('doctrine')->getManager();
        $io = new SymfonyStyle($input, $output);

        $decode = $input->getOption('decode');
        $phone = $input->getArgument('phone');

        if ($decode == true) {
            $io->success('AES encrypt: ' . AES::encrypt($phone));
        } else {
            $io->success('AES decrypt: ' . AES::decrypt($phone));
        }

        return Command::SUCCESS;
    }
}
