#!/bin/sh
set -eu

INSTALL_DIR="${RETPROXY_INSTALL_DIR:-$HOME/.local/bin}"
TARGET="$INSTALL_DIR/retproxy"

remove_path_line() {
  target_dir=$1
  shell_name="$(basename "${SHELL:-sh}")"
  profile="$HOME/.profile"
  case "$shell_name" in
    zsh) profile="$HOME/.zshrc" ;;
    bash) profile="$HOME/.bashrc" ;;
  esac

  line="export PATH=\"$target_dir:\$PATH\""
  if [ -f "$profile" ]; then
    tmp_file="$(mktemp)"
    grep -Fvx "$line" "$profile" > "$tmp_file" || true
    mv "$tmp_file" "$profile"
  fi
}

if [ -f "$TARGET" ]; then
  rm -f "$TARGET"
  echo "Removed $TARGET"
else
  echo "retproxy binary not found at $TARGET"
fi

remove_path_line "$INSTALL_DIR"

echo
echo "retproxy CLI has been uninstalled from this user profile."
echo "Configuration files in ~/.config/retproxy were left in place."
