// Helpers for "Assisted Bodyweight"-style exercises.
//
// Assistance is stored as a NEGATIVE assisted_weight everywhere (least
// negative = least assistance = strongest), matching what the workout-session
// flow already enforces on save. These helpers let the manual-performance and
// PR endpoints apply the same rule.

export function isAssistedCategory(category: any): boolean {
  const en = category?.name?.en;
  return typeof en === "string" && en.toLowerCase().includes("assist");
}

// Move the client-sent assistance into `assisted_weight` as a negative number,
// whether it arrived positive, negative, or (from older app builds) under
// `weight`. Objects without an assistance value pass through untouched.
export function normalizeAssistedSet<
  T extends { weight?: number | null; assisted_weight?: number | null },
>(set: T): T {
  const raw = set.assisted_weight ?? set.weight;
  if (raw == null) return set;
  return { ...set, assisted_weight: -Math.abs(Number(raw)), weight: null } as T;
}
