// Code generated by mdatagen. DO NOT EDIT.

package metadata

import (
	"fmt"
	"strconv"

	"go.opentelemetry.io/collector/pdata/pcommon"
	"go.opentelemetry.io/collector/pdata/xpdata/entity"
)

// TestEntityEntity represents a test.entity entity.
// Create one with NewTestEntityEntity and pass it to EmitForEntity.
type TestEntityEntity struct {
	stringResourceAttr string
	mapResourceAttr    map[string]any
}

// NewTestEntityEntity creates a new TestEntityEntity.
// Identity attributes are required and must be provided at construction time.
func NewTestEntityEntity(stringResourceAttr string) *TestEntityEntity {
	return &TestEntityEntity{
		stringResourceAttr: stringResourceAttr,
	}
}

// Description attribute setters for test.entity.

// SetMapResourceAttr sets the map.resource.attr description attribute.
func (e *TestEntityEntity) SetMapResourceAttr(val map[string]any) {
	e.mapResourceAttr = val
}

// copyToResource populates res with the entity's attributes according to cfg.
// If all identity attributes are enabled, an entity ref is produced; otherwise
// the enabled attributes are written directly as plain resource attributes.
func (e *TestEntityEntity) copyToResource(cfg ResourceAttributesConfig, res pcommon.Resource) {
	if cfg.StringResourceAttr.Enabled {
		ent := entity.ResourceEntities(res).PutEmpty("test.entity")
		ent.IdentifyingAttributes().PutStr("string.resource.attr", e.stringResourceAttr)
		if cfg.MapResourceAttr.Enabled {
			ent.DescriptiveAttributes().PutEmpty("map.resource.attr").SetEmptyMap().FromRaw(e.mapResourceAttr)
		}
	} else {
		if cfg.StringResourceAttr.Enabled {
			res.Attributes().PutStr("string.resource.attr", e.stringResourceAttr)
		}
		if cfg.MapResourceAttr.Enabled {
			res.Attributes().PutEmptyMap("map.resource.attr").FromRaw(e.mapResourceAttr)
		}
	}
}

// TestEntityMetricsBuilder records metrics for the test.entity entity.
// Obtain one via MetricsBuilder.ForTestEntity().
type TestEntityMetricsBuilder struct {
	mb     *MetricsBuilder
	entity *TestEntityEntity
}

// RecordDefaultMetricDataPoint records a data point for the default.metric metric.
func (eb *TestEntityMetricsBuilder) RecordDefaultMetricDataPoint(ts pcommon.Timestamp, val int64, stringAttrAttributeValue string, overriddenIntAttrAttributeValue int64, enumAttrAttributeValue AttributeEnumAttr, sliceAttrAttributeValue []any, mapAttrAttributeValue map[string]any) {
	eb.mb.metricDefaultMetric.recordDataPoint(eb.mb.startTime, ts, val, stringAttrAttributeValue, overriddenIntAttrAttributeValue, enumAttrAttributeValue.String(), sliceAttrAttributeValue, mapAttrAttributeValue)
}

// RecordDefaultMetricToBeRemovedDataPoint records a data point for the default.metric.to_be_removed metric.
func (eb *TestEntityMetricsBuilder) RecordDefaultMetricToBeRemovedDataPoint(ts pcommon.Timestamp, val float64) {
	eb.mb.metricDefaultMetricToBeRemoved.recordDataPoint(eb.mb.startTime, ts, val)
}

// RecordMetricInputTypeDataPoint records a data point for the metric.input_type metric.
func (eb *TestEntityMetricsBuilder) RecordMetricInputTypeDataPoint(ts pcommon.Timestamp, inputVal string, stringAttrAttributeValue string, overriddenIntAttrAttributeValue int64, enumAttrAttributeValue AttributeEnumAttr, sliceAttrAttributeValue []any, mapAttrAttributeValue map[string]any) error {
	val, err := strconv.ParseInt(inputVal, 10, 64)
	if err != nil {
		return fmt.Errorf("failed to parse int64 for MetricInputType, value was %s: %w", inputVal, err)
	}
	eb.mb.metricMetricInputType.recordDataPoint(eb.mb.startTime, ts, val, stringAttrAttributeValue, overriddenIntAttrAttributeValue, enumAttrAttributeValue.String(), sliceAttrAttributeValue, mapAttrAttributeValue)
	return nil
}

// RecordOptionalMetricDataPoint records a data point for the optional.metric metric.
func (eb *TestEntityMetricsBuilder) RecordOptionalMetricDataPoint(ts pcommon.Timestamp, val float64, stringAttrAttributeValue string, booleanAttrAttributeValue bool, booleanAttr2AttributeValue bool) {
	eb.mb.metricOptionalMetric.recordDataPoint(eb.mb.startTime, ts, val, stringAttrAttributeValue, booleanAttrAttributeValue, booleanAttr2AttributeValue)
}

// RecordOptionalMetricEmptyUnitDataPoint records a data point for the optional.metric.empty_unit metric.
func (eb *TestEntityMetricsBuilder) RecordOptionalMetricEmptyUnitDataPoint(ts pcommon.Timestamp, val float64, stringAttrAttributeValue string, booleanAttrAttributeValue bool) {
	eb.mb.metricOptionalMetricEmptyUnit.recordDataPoint(eb.mb.startTime, ts, val, stringAttrAttributeValue, booleanAttrAttributeValue)
}

// RecordReaggregateMetricDataPoint records a data point for the reaggregate.metric metric.
func (eb *TestEntityMetricsBuilder) RecordReaggregateMetricDataPoint(ts pcommon.Timestamp, val float64, stringAttrAttributeValue string, booleanAttrAttributeValue bool) {
	eb.mb.metricReaggregateMetric.recordDataPoint(eb.mb.startTime, ts, val, stringAttrAttributeValue, booleanAttrAttributeValue)
}

// Emit emits all pending metrics for the entity. Resource attributes are filtered by config:
// disabled identity attributes suppress the entity (other enabled attributes are added directly
// to the resource); disabled descriptive/extra attributes are omitted entirely.
func (eb *TestEntityMetricsBuilder) Emit() {
	res := pcommon.NewResource()
	cfg := eb.mb.config.ResourceAttributes
	eb.entity.copyToResource(cfg, res)
	eb.mb.EmitForResource(withResourceMoved(res))
}
