#!/bin/bash

# Notification Hook
# Triggered when Claude Code 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"

EXIT_CODE=$?

if [ $EXIT_CODE -eq 0 ]; then
  log "INFO" "Notification event sent successfully"
else
  log "ERROR" "Failed to send Notification event (exit code: $EXIT_CODE)"
fi

exit $EXIT_CODE
