// Code generated by mdatagen. DO NOT EDIT.

package metadata

import (
	"fmt"

	"go.opentelemetry.io/collector/confmap"
)

// LinuxMemoryAvailableMetricConfig provides config for the linux.memory.available metric.
type LinuxMemoryAvailableMetricConfig struct {
	Enabled          bool `mapstructure:"enabled"`
	enabledSetByUser bool
}

func (ms *LinuxMemoryAvailableMetricConfig) 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
}

// SystemCPUFooMetricConfig provides config for the system.cpu.foo metric.
type SystemCPUFooMetricConfig struct {
	Enabled          bool `mapstructure:"enabled"`
	enabledSetByUser bool
}

func (ms *SystemCPUFooMetricConfig) 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
}

// SystemCPUUtilizationMetricAttributeKey specifies the key of an attribute for the system.cpu.utilization metric.
type SystemCPUUtilizationMetricAttributeKey string

const (
	SystemCPUUtilizationMetricAttributeKeyCPU   SystemCPUUtilizationMetricAttributeKey = "cpu"
	SystemCPUUtilizationMetricAttributeKeyState SystemCPUUtilizationMetricAttributeKey = "state"
)

// SystemCPUUtilizationMetricConfig provides config for the system.cpu.utilization metric.
type SystemCPUUtilizationMetricConfig struct {
	Enabled          bool `mapstructure:"enabled"`
	enabledSetByUser bool

	AggregationStrategy string                                   `mapstructure:"aggregation_strategy"`
	EnabledAttributes   []SystemCPUUtilizationMetricAttributeKey `mapstructure:"attributes"`
}

func (ms *SystemCPUUtilizationMetricConfig) 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
}

func (ms *SystemCPUUtilizationMetricConfig) Validate() error {
	for _, val := range ms.EnabledAttributes {
		switch val {
		case SystemCPUUtilizationMetricAttributeKeyCPU, SystemCPUUtilizationMetricAttributeKeyState:
		default:
			return fmt.Errorf("metric system.cpu.utilization doesn't have an attribute %v, valid attributes: [cpu, state]", val)
		}
	}

	switch ms.AggregationStrategy {
	case AggregationStrategySum, AggregationStrategyAvg, AggregationStrategyMin, AggregationStrategyMax:
	default:
		return fmt.Errorf("invalid aggregation strategy %q, valid strategies: [%s, %s, %s, %s]", ms.AggregationStrategy, AggregationStrategySum, AggregationStrategyAvg, AggregationStrategyMin, AggregationStrategyMax)
	}

	return nil
}

// SystemCPUUtilizationV1MetricAttributeKey specifies the key of an attribute for the system.cpu.utilization@v1 metric.
type SystemCPUUtilizationV1MetricAttributeKey string

const (
	SystemCPUUtilizationV1MetricAttributeKeyCPULogicalNumber SystemCPUUtilizationV1MetricAttributeKey = "cpu.logical_number"
	SystemCPUUtilizationV1MetricAttributeKeyCPUMode          SystemCPUUtilizationV1MetricAttributeKey = "cpu.mode"
)

// SystemCPUUtilizationV1MetricConfig provides config for the system.cpu.utilization@v1 metric.
type SystemCPUUtilizationV1MetricConfig struct {
	Enabled          bool `mapstructure:"enabled"`
	enabledSetByUser bool

	AggregationStrategy string                                     `mapstructure:"aggregation_strategy"`
	EnabledAttributes   []SystemCPUUtilizationV1MetricAttributeKey `mapstructure:"attributes"`
}

func (ms *SystemCPUUtilizationV1MetricConfig) 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
}

func (ms *SystemCPUUtilizationV1MetricConfig) Validate() error {
	for _, val := range ms.EnabledAttributes {
		switch val {
		case SystemCPUUtilizationV1MetricAttributeKeyCPULogicalNumber, SystemCPUUtilizationV1MetricAttributeKeyCPUMode:
		default:
			return fmt.Errorf("metric system.cpu.utilization@v1 doesn't have an attribute %v, valid attributes: [cpu.logical_number, cpu.mode]", val)
		}
	}

	switch ms.AggregationStrategy {
	case AggregationStrategySum, AggregationStrategyAvg, AggregationStrategyMin, AggregationStrategyMax:
	default:
		return fmt.Errorf("invalid aggregation strategy %q, valid strategies: [%s, %s, %s, %s]", ms.AggregationStrategy, AggregationStrategySum, AggregationStrategyAvg, AggregationStrategyMin, AggregationStrategyMax)
	}

	return nil
}

// SystemMemoryLinuxAvailableV1MetricConfig provides config for the system.memory.linux.available@v1 metric.
type SystemMemoryLinuxAvailableV1MetricConfig struct {
	Enabled          bool `mapstructure:"enabled"`
	enabledSetByUser bool
}

func (ms *SystemMemoryLinuxAvailableV1MetricConfig) 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 samplemigration metrics.
type MetricsConfig struct {
	LinuxMemoryAvailable         LinuxMemoryAvailableMetricConfig         `mapstructure:"linux.memory.available"`
	SystemCPUFoo                 SystemCPUFooMetricConfig                 `mapstructure:"system.cpu.foo"`
	SystemCPUUtilization         SystemCPUUtilizationMetricConfig         `mapstructure:"system.cpu.utilization"`
	SystemCPUUtilizationV1       SystemCPUUtilizationV1MetricConfig       `mapstructure:"system.cpu.utilization@v1"`
	SystemMemoryLinuxAvailableV1 SystemMemoryLinuxAvailableV1MetricConfig `mapstructure:"system.memory.linux.available@v1"`
}

func DefaultMetricsConfig() MetricsConfig {
	return MetricsConfig{
		LinuxMemoryAvailable: LinuxMemoryAvailableMetricConfig{
			Enabled: false,
		},
		SystemCPUFoo: SystemCPUFooMetricConfig{
			Enabled: false,
		},
		SystemCPUUtilization: SystemCPUUtilizationMetricConfig{
			Enabled:             true,
			AggregationStrategy: AggregationStrategyAvg,
			EnabledAttributes:   []SystemCPUUtilizationMetricAttributeKey{SystemCPUUtilizationMetricAttributeKeyCPU, SystemCPUUtilizationMetricAttributeKeyState},
		},
		SystemCPUUtilizationV1: SystemCPUUtilizationV1MetricConfig{
			Enabled:             false,
			AggregationStrategy: AggregationStrategySum,
			EnabledAttributes:   []SystemCPUUtilizationV1MetricAttributeKey{SystemCPUUtilizationV1MetricAttributeKeyCPULogicalNumber, SystemCPUUtilizationV1MetricAttributeKeyCPUMode},
		},
		SystemMemoryLinuxAvailableV1: SystemMemoryLinuxAvailableV1MetricConfig{
			Enabled: false,
		},
	}
}

// MetricsBuilderConfig is a configuration for samplemigration metrics builder.
type MetricsBuilderConfig struct {
	Metrics MetricsConfig `mapstructure:"metrics"`
}

func NewDefaultMetricsBuilderConfig() MetricsBuilderConfig {
	return MetricsBuilderConfig{
		Metrics: DefaultMetricsConfig(),
	}
}

// Deprecated: Use NewDefaultMetricsBuilderConfig.
func DefaultMetricsBuilderConfig() MetricsBuilderConfig {
	return NewDefaultMetricsBuilderConfig()
}
