#!/usr/bin/env bash
set -Eeuo pipefail
PROFILE_NAME="${CHATGPT_COMPUTER_MCP_PROFILE:-chatgpt-computer-mcp}"
SERVICE_NAME="chatgpt-computer-mcp-tunnel.service"
SYSTEMD_UNIT="$HOME/.config/systemd/user/$SERVICE_NAME"
USER_LIB="$HOME/.local/lib/chatgpt-computer-mcp"
PROFILE_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/tunnel-client"
PROFILE_FILE="$PROFILE_DIR/$PROFILE_NAME.yaml"

systemctl --user disable --now "$SERVICE_NAME" 2>/dev/null || true
rm -f "$SYSTEMD_UNIT"
rm -rf "$USER_LIB"
systemctl --user daemon-reload 2>/dev/null || true
if [[ -f "$PROFILE_FILE" ]]; then
  mv "$PROFILE_FILE" "$PROFILE_FILE.disabled.$(date +%Y%m%d-%H%M%S)"
fi
printf "Removed the persistent tunnel service and disabled profile '%s'.\n" "$PROFILE_NAME"
printf 'Repository files, config.local.json, and .secrets were left untouched.\n'
