<?php

declare(strict_types=1);

namespace App\Framework\Telemetry\Config;

/**
 * Configuration for a telemetry exporter
 */
final class ExporterConfig
{
    /**
     * @param string $endpoint Endpoint URL for the exporter
     * @param string $protocol Protocol to use (http, file, etc.)
     * @param array<string, mixed> $options Additional options for the exporter
     */
    public function __construct(
        private readonly string $endpoint,
        private readonly string $protocol = 'http',
        private readonly array $options = [],
    ) {
    }

    /**
     * Get endpoint URL
     */
    public function getEndpoint(): string
    {
        return $this->endpoint;
    }

    /**
     * Get protocol
     */
    public function getProtocol(): string
    {
        return $this->protocol;
    }

    /**
     * Get all options
     *
     * @return array<string, mixed>
     */
    public function getOptions(): array
    {
        return $this->options;
    }

    /**
     * Get a specific option
     */
    public function getOption(string $name, mixed $default = null): mixed
    {
        return $this->options[$name] ?? $default;
    }

    /**
     * Check if an option exists
     */
    public function hasOption(string $name): bool
    {
        return isset($this->options[$name]);
    }

    /**
     * Check if this is an HTTP exporter
     */
    public function isHttpExporter(): bool
    {
        return $this->protocol === 'http' || $this->protocol === 'https';
    }

    /**
     * Check if this is a file exporter
     */
    public function isFileExporter(): bool
    {
        return $this->protocol === 'file';
    }

    /**
     * Create a new instance with additional options
     *
     * @param array<string, mixed> $options
     */
    public function withOptions(array $options): self
    {
        return new self(
            $this->endpoint,
            $this->protocol,
            array_merge($this->options, $options)
        );
    }
}
