#!/bin/sh
# ollie-ask: one-shot prompt helper for Dolphin service menus
# Usage: ollie-ask <file_or_dir> [prompt_prefix]

TARGET="$1"
PREFIX="${2:-Describe and explain this file:}"
PROMPT="$PREFIX $TARGET"

SERVICE="org.ollie.SessionManager"
OBJ="/org/ollie/SessionManager"
IFACE="org.ollie.SessionManager"

# Use Generate one-shot — no session needed
RESULT=$(gdbus call --session --dest $SERVICE --object-path $OBJ \
    --method $IFACE.Generate "$PROMPT" "" "" "" 2>/dev/null | \
    sed "s/^('//; s/')$//; s/\\\\n/\n/g")

if [ -z "$RESULT" ]; then
    notify-send "Ollie" "No response (is olliesrv or ollied running?)"
    exit 1
fi

# Show result
TMPFILE=$(mktemp /tmp/ollie-ask.XXXXXX)
printf '%s' "$RESULT" > "$TMPFILE"

if command -v kdialog > /dev/null 2>&1; then
    kdialog --title "Ollie — $(basename "$TARGET")" --textbox "$TMPFILE" 600 400
elif command -v zenity > /dev/null 2>&1; then
    zenity --text-info --title="Ollie — $(basename "$TARGET")" --width=600 --height=400 --filename="$TMPFILE"
else
    notify-send -t 30000 "Ollie" "$RESULT"
fi

rm -f "$TMPFILE"
