#!/bin/bash
# filepath: uninstall.sh

set -e

if [ "$EUID" -ne 0 ]; then 
    echo "Please run as root (use sudo)"
    exit 1
fi

echo "Uninstalling Voice Agent..."

if systemctl is-active --quiet chenxing_agent_service 2>/dev/null; then
    systemctl stop chenxing_agent_service
fi
systemctl disable chenxing_agent_service 2>/dev/null || true
rm -f /etc/systemd/system/chenxing_agent_service.service
systemctl daemon-reload

rm -rf /opt/voice-agent
rm -rf /etc/voice-agent
rm -f /opt/.env
rm -f /opt/res
echo "Voice Agent uninstalled successfully"
echo ""
echo "Note: Logs are preserved in /var/log/voice-agent"
echo "      Remove manually if needed: sudo rm -rf /var/log/voice-agent"
rm -rf /opt/config

echo "✅ Uninstallation completed."
echo "Configuration preserved in /etc/voice-agent"
echo "To remove config: sudo rm -rf /etc/voice-agent"
