#!/bin/bash

# Manual setup for Super+Alt+D keybinding
# Use this if the automated script has issues

echo "🔧 Manual Super+Alt+D Keybinding Setup"

# Get next available keybinding number
KEYBASE="/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings"
LAST_KEY=$(gsettings list-keys $KEYBASE | sort -n | tail -1 2>/dev/null || echo "custom0")
NEXT_NUM=$((${LAST_KEY#custom} + 1))
KEYPATH="$KEYBASE/custom$NEXT_NUM"

echo "Creating Super+Alt+D keybinding at: $KEYPATH"

# Set up the Super+Alt+D keybinding for conversation mode
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$NEXT_NUM/ name "Toggle AI Conversation"
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$NEXT_NUM/ command "/mnt/storage/Development/dictation-service/scripts/toggle-conversation.sh"
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$NEXT_NUM/ binding "<Super><Alt>d"

# Add to the keybindings list
FULL_KEYPATH="/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$NEXT_NUM"
CURRENT_LIST=$(gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings)
if [[ $CURRENT_LIST == "@as []" ]]; then
    NEW_LIST="['$FULL_KEYPATH']"
else
    NEW_LIST="${CURRENT_LIST%]}, '$FULL_KEYPATH']"
fi

gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "$NEW_LIST"

echo "✅ Super+Alt+D keybinding setup complete!"
echo "🤖 Press Super+Alt+D (Windows+Alt+D) to start AI conversation"