<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Extensions;

use PpPhp\Core\Platform\Manifest\ManifestManager;

final class ExtensionManager
{
    public function __construct(
        private readonly ManifestManager $manifests,
        private readonly string $type
    ) {}

    public function all(): array
    {
        return $this->manifests->byType($this->type);
    }

    public function enabled(): array
    {
        return array_values(array_filter($this->all(), static fn ($manifest): bool => $manifest->enabled()));
    }

    public function count(): int
    {
        return count($this->all());
    }

    public function find(string $id)
    {
        return $this->manifests->find($this->type, $id);
    }

    public function toArray(): array
    {
        return array_map(static fn ($manifest): array => $manifest->toArray(), $this->all());
    }
}
