<?php

declare(strict_types=1);

namespace PpPhp\Core\Diagnostics\Providers;

use PpPhp\Core\Diagnostics\Context\DiagnosticContext;
use PpPhp\Core\Diagnostics\Results\DiagnosticResult;

final class PlatformDiagnosticsProvider extends AbstractDiagnosticProvider
{
    public function id(): string
    {
        return 'platform';
    }

    public function label(): string
    {
        return 'Platform';
    }

    public function description(): string
    {
        return 'Checks core PPphp platform identity and required folders.';
    }

    public function priority(): int
    {
        return 10;
    }

    public function diagnose(DiagnosticContext $context): DiagnosticResult
    {
        $result = new DiagnosticResult($this->id(), $this->label(), 'platform');

        if (is_file($context->path('platform.json'))) {
            $result->info('platform.json found.', 'platform.json');
        } else {
            $result->warning('platform.json missing.', 'platform.json', 'Create platform.json to identify PPphp platform metadata.', true);
        }

        foreach (['core', 'modules', 'plugins', 'packages', 'public'] as $folder) {
            if (!is_dir($context->path($folder))) {
                $result->warning('Expected platform folder missing: ' . $folder, $folder, 'Create this folder if the subsystem is required.', true);
            }
        }

        return $result;
    }
}
