package agentbuild

// O11yDedicatedToleration matches the `o11y-dedicated=o11y:NoExecute` taint that
// is applied to every o11y-dedicated node pool (see o11yk8sagent/o11ytidbagent
// controllers).
func O11yDedicatedToleration() map[string]any {
	return map[string]any{
		"key":      "o11y-dedicated",
		"operator": "Equal",
		"value":    "o11y",
		"effect":   "NoExecute",
	}
}

// O11yProjectToleration matches the per-project `o11y-project=<projectID>:NoExecute`
// taint on the dedicated node pool.
func O11yProjectToleration(projectID string) map[string]any {
	return map[string]any{
		"key":      "o11y-project",
		"operator": "Equal",
		"value":    projectID,
		"effect":   "NoExecute",
	}
}

// MergeOperatorChartValues returns a shallow copy of the supplied helm chart
// values with default tolerations for the o11y-dedicated node taints injected.
//
// If the caller already specified a `tolerations` key in the chart values, the
// caller's value is kept untouched so explicit overrides keep working.
func MergeOperatorChartValues(values map[string]any, projectID string) map[string]any {
	out := make(map[string]any, len(values)+1)
	for k, v := range values {
		out[k] = v
	}
	if _, ok := out["tolerations"]; !ok {
		out["tolerations"] = []map[string]any{
			O11yDedicatedToleration(),
			O11yProjectToleration(projectID),
		}
	}
	return out
}
