package api

import "context"

// ContextKey is a typed string used for context keys in this package.
type ContextKey string

// KubernetesIDCtxKey is the context key for the kubernetes ID. External callers
// can use it to set the value directly:
//
//	ctx = context.WithValue(ctx, api.KubernetesIDCtxKey, "my-branch")
//
// or use the convenience helper WithKubernetesID.
const KubernetesIDCtxKey ContextKey = "kubernetesID"

// KubernetesIDHeader is the HTTP header name injected when the context carries a kubernetes ID.
const KubernetesIDHeader = "X-Kubernetes-Id"

// WithKubernetesID returns a new context with the given kubernetes ID.
// The kubernetes ID will be injected as the X-Kubernetes-Id header in all
// subsequent o11y API requests made with the returned context.
func WithKubernetesID(ctx context.Context, kubernetesID string) context.Context {
	return context.WithValue(ctx, KubernetesIDCtxKey, kubernetesID)
}

// KubernetesIDFromContext extracts the kubernetes ID from the context, if set.
// Returns an empty string if not present.
func KubernetesIDFromContext(ctx context.Context) string {
	if v, ok := ctx.Value(KubernetesIDCtxKey).(string); ok {
		return v
	}
	return ""
}
