<?php

namespace AutoAdmin\Bundle\Core\Command;

use AutoAdmin\Bundle\Core\Helper\CacheSuffixHelper;
use Exception;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(name: 'aa:util:cache-suffix-refresh')]
class CacheSuffixCommand extends Command
{
    protected CacheSuffixHelper $cacheSuffixHelper;

    public function setCacheSuffixHelper(CacheSuffixHelper $cacheSuffixHelper)
    {
        $this->cacheSuffixHelper = $cacheSuffixHelper;
    }

    protected function configure()
    {
        $this
            ->setDescription('Update or create cache suffix file');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);

        try {
            $this->cacheSuffixHelper->refreshSuffixFile();
        } catch (Exception $e) {
            $io->error($e->getMessage());
        }

        return 0;
    }
}
