#!/bin/sh
set -e

# $1 is the argument passed by Debian (remove, purge, upgrade, etc.)
case "$1" in
    remove|purge)
        echo "Cleaning up FUSS SpeechToText: removing AI models and temporary files..."

        # Remove the entire installation directory to delete files downloaded via wget
        if [ -d "/opt/fuss-speechtotext" ]; then
            rm -rf "/opt/fuss-speechtotext"
            echo "Directory /opt/fuss-speechtotext removed."
        fi

        # Update system desktop and icon databases to reflect the removal
        if command -v update-desktop-database >/dev/null 2>&1; then
            update-desktop-database -q
        fi
        if command -v gtk-update-icon-cache >/dev/null 2>&1; then
            gtk-update-icon-cache -f -t /usr/share/pixmaps >/dev/null 2>&1 || true
        fi
        
        echo "Uninstallation completed."
    ;;

    upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
        # Do not remove models during a simple software upgrade
    ;;

    *)
        echo "postrm called with unknown argument: \`$1'" >&2
        exit 1
    ;;
esac

exit 0
