// Code generated by mdatagen. DO NOT EDIT.

package {{ .Package }}

{{ if or .Metrics .ResourceAttributes -}}
import "go.opentelemetry.io/collector/confmap"
{{- end }}

{{ if .Metrics -}}

// MetricConfig provides common config for a particular metric.
type MetricConfig struct {
	Enabled bool `mapstructure:"enabled"`

	enabledSetByUser bool
}

func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error {
	if parser == nil {
		return nil
	}
	err := parser.Unmarshal(ms)
	if err != nil {
		return err
	}
	ms.enabledSetByUser = parser.IsSet("enabled")
	return nil
}

// MetricsConfig provides config for {{ .Type }} metrics.
type MetricsConfig struct {
	{{- range $name, $metric := .Metrics }}
	{{ $name.Render }} MetricConfig `mapstructure:"{{ $name }}"`
	{{- end }}
}

func DefaultMetricsConfig() MetricsConfig {
	return MetricsConfig{
		{{- range $name, $metric := .Metrics }}
		{{ $name.Render }}: MetricConfig{
			Enabled: {{ $metric.Enabled }},
		},
		{{- end }}
	}
}
{{- end }}

{{ if .ResourceAttributes -}}
// ResourceAttributeConfig provides common config for a particular resource attribute.
type ResourceAttributeConfig struct {
	Enabled bool `mapstructure:"enabled"`

	enabledSetByUser bool
}

func (rac *ResourceAttributeConfig) Unmarshal(parser *confmap.Conf) error {
	if parser == nil {
		return nil
	}
	err := parser.Unmarshal(rac)
	if err != nil {
		return err
	}
	rac.enabledSetByUser = parser.IsSet("enabled")
	return nil
}

// ResourceAttributesConfig provides config for {{ .Type }} resource attributes.
type ResourceAttributesConfig struct {
	{{- range $name, $attr := .ResourceAttributes }}
	{{ $name.Render }} ResourceAttributeConfig `mapstructure:"{{ $name }}"`
	{{- end }}
}

func DefaultResourceAttributesConfig() ResourceAttributesConfig {
	return ResourceAttributesConfig{
		{{- range $name, $attr := .ResourceAttributes }}
		{{ $name.Render }}: ResourceAttributeConfig {
			Enabled: {{ $attr.Enabled }},
		},
		{{- end }}
	}
}
{{- end }}

{{ if .Metrics -}}
// MetricsBuilderConfig is a configuration for {{ .Type }} metrics builder.
type MetricsBuilderConfig struct {
	Metrics MetricsConfig `mapstructure:"metrics"`
	{{- if .ResourceAttributes }}
	ResourceAttributes ResourceAttributesConfig `mapstructure:"resource_attributes"`
	{{- end }}
}

func DefaultMetricsBuilderConfig() MetricsBuilderConfig {
	return MetricsBuilderConfig {
		Metrics: DefaultMetricsConfig(),
		{{- if .ResourceAttributes }}
		ResourceAttributes: DefaultResourceAttributesConfig(),
		{{- end }}
	}
}
{{- end }}
