<?php

declare(strict_types=1);

namespace PpPhp\Core\Maintenance\Providers;

use PpPhp\Core\Maintenance\Contracts\MaintenanceProviderInterface;
use PpPhp\Core\Maintenance\Results\MaintenanceResult;

final class PlatformBasicsProvider implements MaintenanceProviderInterface
{
    public function id(): string
    {
        return 'platform-basics';
    }

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

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

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

    public function run(string $basePath): MaintenanceResult
    {
        $result = new MaintenanceResult($this->id(), $this->label());

        foreach (['core', 'modules', 'plugins', 'packages', 'public'] as $folder) {
            if (!is_dir(rtrim($basePath, '/') . '/' . $folder)) {
                $result->warning(
                    'Expected folder is missing: ' . $folder,
                    $folder,
                    'Create the folder if this PPphp installation should support this subsystem.'
                );
            }
        }

        if (!is_file(rtrim($basePath, '/') . '/platform.json')) {
            $result->warning(
                'platform.json is missing.',
                'platform.json',
                'Create platform.json to identify platform version, schema versions and local-first configuration.'
            );
        } else {
            $result->info('platform.json found.', 'platform.json');
        }

        return $result;
    }
}
