<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Manifest;

final class ManifestRepository
{
    private ManifestCollection $collection;

    public function __construct(?ManifestCollection $collection = null)
    {
        $this->collection = $collection ?? new ManifestCollection();
    }

    public function setCollection(ManifestCollection $collection): void
    {
        $this->collection = $collection;
    }

    public function collection(): ManifestCollection
    {
        return $this->collection;
    }

    public function all(): array
    {
        return $this->collection->all();
    }

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

    public function find(string $type, string $id): ?ManifestRecord
    {
        return $this->collection->get($type, $id);
    }

    public function findById(string $id): ?ManifestRecord
    {
        return $this->collection->getById($id);
    }
}
