export function paramNameFor(entityKeyLocal: string): string {
  const parts = entityKeyLocal.split(':')
  const key = parts[parts.length - 1]
  return `${key}Id`
}

/**
 * Ensures the path starts with a single leading slash and has no trailing slash (except root '/')
 * @param path The path fragment to normalize
 */
export function ensureLeadingSlash(path: string): string {
  const trimmed = path.trim()
  const withSlash = trimmed.startsWith('/') ? trimmed : `/${trimmed}`
  if (withSlash === '/') return '/'
  return withSlash.replace(/\/+$/, '')
}

/**
 * Joins two absolute-like fragments ensuring single slashes between segments
 * @param left The left path fragment
 * @param right The right path fragment
 */
export function joinPaths(left: string, right: string): string {
  const l = left.endsWith('/') ? left.slice(0, -1) : left
  const r = right.startsWith('/') ? right : `/${right}`
  return `${l}${r}`
}
