<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Developer;

use PpPhp\Core\Platform\Bootstrap\PlatformBootstrap;
use PpPhp\Core\Platform\Kernel\Platform;

final class PlatformCacheManager
{
    public function build(): array
    {
        $loader = PlatformBootstrap::loader();

        if ($loader) {
            $loader->buildClassMap();
            $loader->saveCache();
        }

        Platform::manifests()->reload();

        return [
            'classmap' => $loader ? $loader->count() : 0,
            'manifests' => count(Platform::manifests()->all()),
        ];
    }

    public function clear(): array
    {
        $loader = PlatformBootstrap::loader();

        if ($loader) {
            $loader->clearCache();
        }

        Platform::manifests()->cache()->clear();

        return [
            'cleared' => true,
        ];
    }

    public function warm(): array
    {
        return $this->build();
    }
}
