<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;
use PpPhp\Core\Platform\Developer\PlatformDoctor;

final class DoctorCommand extends AbstractCommand
{
    public function name(): string { return 'doctor'; }
    public function description(): string { return 'Diagnose platform health.'; }

    public function handle(array $arguments = []): int
    {
        $report = (new PlatformDoctor())->diagnose();

        $this->title('PPphp Platform Doctor');
        $this->line('Health Score: ' . $report['healthScore'] . '%');
        $this->line('Errors: ' . $report['errors'] . ' | Warnings: ' . $report['warnings']);
        $this->line();

        if ($report['issues'] === []) {
            $this->line('No issues found.');
        } else {
            foreach ($report['issues'] as $issue) {
                $this->line(strtoupper($issue['severity']) . ': ' . $issue['message']);
            }
        }

        return $report['errors'] > 0 ? 1 : 0;
    }
}
