<?php

declare(strict_types=1);

namespace App\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(name: 'subs:list', description: 'GET /subscriptions — list registered webhooks.')]
final class ListSubscriptionsCommand extends AbstractCommand
{

    protected function doExecute(SymfonyStyle $io, InputInterface $input, OutputInterface $output): int
    {
        $subs = $this->api->subscriptions->getSubscriptions();
        if ($subs->subscriptions === []) {
            $io->text('(no subscriptions)');
            return self::SUCCESS;
        }
        $rows = [];
        foreach ($subs->subscriptions as $s) {
            $rows[] = [$s->url, $s->version ?? '—', implode(',', $s->updateTypes) ?: '(all)'];
        }
        $io->table(['url', 'version', 'update_types'], $rows);
        return self::SUCCESS;
    }
}
