<?php

declare(strict_types=1);

namespace PpPhp\Core\Manifest;

final class ManifestDiscoveryResult
{
    /** @var Manifest[] */
    private array $manifests = [];

    /** @var string[] */
    private array $errors = [];

    public function add(Manifest $manifest): void
    {
        $this->manifests[] = $manifest;
    }

    public function error(string $message): void
    {
        $this->errors[] = $message;
    }

    /** @return Manifest[] */
    public function manifests(): array
    {
        return $this->manifests;
    }

    /** @return string[] */
    public function errors(): array
    {
        return $this->errors;
    }

    public function toArray(): array
    {
        return [
            'manifests' => array_map(
                static fn (Manifest $manifest): array => $manifest->toArray(),
                $this->manifests
            ),
            'errors' => $this->errors,
        ];
    }
}
