#!/bin/bash
set -e

echo "🗑️ Removing PMAT - Pragmatic AI MCP Agent Toolkit"

case "$1" in
    remove|deconfigure)
        # Stop and disable the service
        if command -v systemctl >/dev/null 2>&1; then
            echo "🛑 Stopping PMAT agent service..."
            systemctl stop pmat-agent.service || true
            systemctl disable pmat-agent.service || true
            echo "✅ Service stopped and disabled"
        fi

        # Note: We don't remove the pmat user or directories here
        # This allows data persistence if user reinstalls
        # For complete removal, use: userdel pmat; rm -rf /var/lib/pmat-agent /var/log/pmat-agent
        
        echo ""
        echo "ℹ️ Package removed successfully!"
        echo "📝 Note: Service user and data directories preserved"
        echo "   For complete cleanup, run:"
        echo "   sudo userdel pmat"
        echo "   sudo rm -rf /var/lib/pmat-agent /var/log/pmat-agent"
        ;;
esac

exit 0