package nodegroup

import (
	"strings"
)

// NormalizeInstanceType converts a cloud instance type to a DNS-compatible lowercase name segment.
// K8s NodeGroup names must follow RFC 1123 label format (lowercase alphanumeric and '-'),
// so '.' and '_' are replaced with '-' and the result is converted to lowercase.
//
// This conversion is safe within a single deployment because cloud providers use
// non-overlapping separator conventions:
//   - AWS: '.' (m5.2xlarge)    → m5-2xlarge
//   - GCP: '-' (n2-standard-8) → n2-standard-8 (no change)
//   - Azure: '_' (Standard_D8s_v3) → standard-d8s-v3
//
// Note: The returned name uses the normalized lowercase form, not the original.
// To get the original cloud instance type, look it up from NodeInstanceGroup config.
func NormalizeInstanceType(instanceType string) string {
	r := strings.NewReplacer(".", "-", "_", "-")
	return strings.ToLower(r.Replace(instanceType))
}
