<?php

declare(strict_types=1);

namespace PpPhp\Core\Diagnostics\Context;

final class DiagnosticContext
{
    private array $data = [];

    public function __construct(
        private readonly string $basePath,
        array $data = []
    ) {
        $this->data = $data;
    }

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

    public function path(string $relative): string
    {
        return rtrim($this->basePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($relative, DIRECTORY_SEPARATOR);
    }

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

    public function get(string $key, mixed $default = null): mixed
    {
        return $this->data[$key] ?? $default;
    }

    public function has(string $key): bool
    {
        return array_key_exists($key, $this->data);
    }

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