package files

import (
	"strings"
)

// NormalizeParentObjectAPIName returns a stable API name for persisted file rows.
// It prefers the object inferred from the record ID when available. Otherwise
// the caller-provided API name is returned as authored; object-name casing is
// metadata-owned, not a runtime CRM alias table.
func NormalizeParentObjectAPIName(parentID, parentObjectAPIName string, resolve func(recordID string) (string, bool)) string {
	parentID = strings.TrimSpace(parentID)
	parentObjectAPIName = strings.TrimSpace(parentObjectAPIName)

	if resolve != nil {
		inferred, ok := resolve(parentID)
		if ok && (parentObjectAPIName == "" || strings.EqualFold(parentObjectAPIName, inferred)) {
			return inferred
		}
	}

	return parentObjectAPIName
}
