<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Modules;

use PpPhp\Core\Platform\Manifest\ManifestManager;

final class ModuleManager
{
    private ModuleCollection $collection;

    public function __construct(
        private readonly ManifestManager $manifests
    ) {
        $this->collection = new ModuleCollection();
    }

    public function load(): ModuleCollection
    {
        $this->collection = new ModuleCollection();

        foreach ($this->manifests->modules() as $manifest) {
            $this->collection->add(new ModuleRecord($manifest));
        }

        return $this->collection;
    }

    public function all(): array { return $this->collection->all(); }
    public function enabled(): array { return $this->collection->enabled(); }
    public function has(string $id): bool { return $this->collection->has($id); }
    public function get(string $id): ?ModuleRecord { return $this->collection->get($id); }
    public function count(): int { return $this->collection->count(); }
    public function collection(): ModuleCollection { return $this->collection; }
}
