<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\DI\Compiler;

use PpPhp\Core\Platform\DI\Repository\DefinitionRepository;

final class CompilerContext
{
    private array $compiled = [];
    private array $warnings = [];
    private array $metadata = [];

    public function __construct(
        private readonly DefinitionRepository $definitions,
        private readonly string $basePath
    ) {}

    public function definitions(): DefinitionRepository { return $this->definitions; }
    public function basePath(): string { return $this->basePath; }

    public function addCompiled(CompiledDefinition $definition): void
    {
        $this->compiled[$definition->id()] = $definition;
    }

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

    public function warning(string $message, array $metadata = []): void
    {
        $this->warnings[] = ['message' => $message, 'metadata' => $metadata];
    }

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

    public function setMetadata(string $key, mixed $value): void
    {
        $this->metadata[$key] = $value;
    }

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