package utils

import (
	"strconv"
	"strings"
)

// DeriveBaseName removes trailing numeric tokens from the flock name.
func DeriveBaseName(name string) string {
	trimmed := strings.TrimSpace(name)
	if trimmed == "" {
		return ""
	}

	parts := strings.Fields(trimmed)
	for len(parts) > 0 {
		if _, err := strconv.Atoi(parts[len(parts)-1]); err == nil {
			parts = parts[:len(parts)-1]
			continue
		}
		break
	}

	return strings.TrimSpace(strings.Join(parts, " "))
}
