function inviteCodeLast4(inviteCode) {
  if (!inviteCode || typeof inviteCode !== "string") return "none";
  const trimmed = inviteCode.trim();
  if (!trimmed) return "none";
  return trimmed.slice(-4);
}

function safeErrorMessage(error) {
  if (!error) return "unknown_error";
  if (typeof error === "string") return error;
  if (typeof error.message === "string" && error.message.trim()) {
    return error.message;
  }
  return "unknown_error";
}

module.exports = {
  inviteCodeLast4,
  safeErrorMessage,
};
