// Code generated by mdatagen. DO NOT EDIT.

package otlpreceiver

import (
	"errors"

	"go.opentelemetry.io/collector/component"
	"go.opentelemetry.io/collector/config/configgrpc"
	"go.opentelemetry.io/collector/config/confighttp"
	"go.opentelemetry.io/collector/config/configoptional"
	"go.opentelemetry.io/collector/config/configtls"
)

type HTTPConfig struct {
	// ServerConfig defines settings for creating an HTTP server.
	ServerConfig confighttp.ServerConfig `mapstructure:",squash"`

	// TracesURLPath is the URL path to receive traces on. If omitted "/v1/traces" will be used.
	TracesURLPath SanitizedURLPath `mapstructure:"traces_url_path,omitempty"`

	// MetricsURLPath is the URL path to receive metrics on. If omitted "/v1/metrics" will be used.
	MetricsURLPath SanitizedURLPath `mapstructure:"metrics_url_path,omitempty"`

	// LogsURLPath is the URL path to receive logs on. If omitted "/v1/logs" will be used.
	LogsURLPath SanitizedURLPath `mapstructure:"logs_url_path,omitempty"`

	// prevent unkeyed literal initialization
	_ struct{}
}

func newDefaultHTTPConfig() HTTPConfig {
	return HTTPConfig{
		ServerConfig: confighttp.NewDefaultServerConfig(),
	}
}

// Protocols is the configuration for the supported protocols, currently gRPC and HTTP (Proto and JSON).
type Protocols struct {
	// GRPC defines common settings for a gRPC server configuration.
	GRPC configoptional.Optional[configgrpc.ServerConfig] `mapstructure:"grpc"`

	HTTP configoptional.Optional[HTTPConfig] `mapstructure:"http"`

	// prevent unkeyed literal initialization
	_ struct{}
}

// Validate validates the Protocols fields according to schema annotations.
// Called by confmap on config resolution. Don't call it explicitly to avoid duplicate errors.
func (c *Protocols) Validate() error {
	var err error

	if inner_err := validateProtocols(c); inner_err != nil {
		err = errors.Join(err, inner_err)
	}

	return err
}

func newDefaultProtocols() Protocols {
	grpc := configgrpc.NewDefaultServerConfig()
	grpc.ReadBufferSize = 524288
	grpc.NetAddr.Endpoint = "localhost:4317"
	http := newDefaultHTTPConfig()
	http.ServerConfig.NetAddr.Endpoint = "localhost:4318"
	http.ServerConfig.TLS = configoptional.None[configtls.ServerConfig]()
	http.ServerConfig.ReadHeaderTimeout = 0
	http.ServerConfig.WriteTimeout = 0
	http.TracesURLPath = "/v1/traces"
	http.MetricsURLPath = "/v1/metrics"
	http.LogsURLPath = "/v1/logs"
	return Protocols{
		GRPC: configoptional.Default(grpc),
		HTTP: configoptional.Default(http),
	}
}

type SanitizedURLPath string

// Config defines the configuration for OTLP Receiver component.
type Config struct {
	// Protocols is the configuration for the supported protocols, currently gRPC and HTTP (Proto and JSON).
	Protocols Protocols `mapstructure:"protocols"`

	// prevent unkeyed literal initialization
	_ struct{}
}

func createDefaultConfig() component.Config {
	return &Config{
		Protocols: newDefaultProtocols(),
	}
}
