#!/bin/bash

# Notification Hook
# Triggered when Gemini CLI shows a notification
# Forwards notifications to mobile app

# Source common utilities
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/common.sh"

log "INFO" "Notification hook triggered"

# Read JSON input from stdin
INPUT=$(read_json_input)

log "DEBUG" "Input: $INPUT"

# Extract session ID for dynamic port lookup
SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // empty')

# Send to MCP server
send_to_mcp "event" "$INPUT" "$SESSION_ID"

if [ $? -eq 0 ]; then
  log "INFO" "Notification event sent successfully"
else
  log "ERROR" "Failed to send Notification event"
fi

# Always exit 0 so Gemini CLI continues normally
exit 0
