<?php

namespace App\Console\Commands;

use App\Services\ReleaseChecker;
use Illuminate\Console\Command;

/**
 * Refresh the cached latest-release tag so the global sidebar update badge stays accurate without
 * the operator first opening the Versions page. Anonymous + read-only against the public Git host.
 */
class CheckUpdate extends Command
{
    protected $signature = 'clusev:check-update';

    protected $description = 'Refresh the cached latest-release tag (keeps the sidebar update badge warm).';

    public function handle(ReleaseChecker $checker): int
    {
        $tag = $checker->refresh();
        $this->info($tag !== null ? "latest release: v{$tag}" : 'remote unreachable — keeping the previous cache');

        return self::SUCCESS;
    }
}
