<?php

namespace App\Console\Commands;

use App\Services\Help\HelpSyncService;
use Illuminate\Console\Command;

class SyncHelpCenter extends Command
{
    protected $signature = 'help:sync';

    protected $description = 'Compile markdown help articles into cached JSON bundles.';

    public function handle(HelpSyncService $service): int
    {
        $result = $service->sync();

        foreach ($result as $audience => $locales) {
            foreach ($locales as $locale => $count) {
                $this->components->info(sprintf('Synced %d %s/%s articles', $count, $audience, $locale));
            }
        }

        $this->components->success('Help center cache updated.');

        return self::SUCCESS;
    }
}
