#!/bin/bash
# update_ivr.sh — run on Hostinger server after creating the combined agent
#
# Usage:
#   chmod +x update_ivr.sh
#   ./update_ivr.sh
#
# Replace COMBINED-AGENT-UUID-HERE with the actual UUID before running.

BOLNA_KEY="bn-49a825cc53fb4aa99a5e9452239bb110"
EMERGENCY_AGENT="d7c89c7c-8957-4bae-a9ac-ec6be2a752a9"
COMBINED_AGENT="18ec6048-91c3-4813-b5a3-e7761145b78e"

echo "=== Step 1: List phone numbers ==="
curl -s -X GET "https://api.bolna.ai/phone-numbers" \
  -H "Authorization: Bearer $BOLNA_KEY" \
  -H "Content-Type: application/json" \
  | python3 -m json.tool

echo ""
echo "=== Step 2: Update IVR (copy the phone number ID from above and paste below) ==="
echo "Enter phone number ID from the list above:"
read PHONE_ID

echo ""
echo "Updating IVR for phone ID: $PHONE_ID"

curl -s -X PATCH "https://api.bolna.ai/phone-numbers/$PHONE_ID" \
  -H "Authorization: Bearer $BOLNA_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"agent_welcome_message\": \"नमस्कार, Forbaxy Hospitals में आपका स्वागत है। Emergency के लिए 1 दबाएं। Appointment या किसी भी अन्य जानकारी के लिए 2 दबाएं।\",
    \"dtmf_options\": {
      \"1\": {
        \"agent_id\": \"$EMERGENCY_AGENT\",
        \"call_reason\": \"Emergency\"
      },
      \"2\": {
        \"agent_id\": \"$COMBINED_AGENT\",
        \"call_reason\": \"Appointment & General\"
      }
    },
    \"no_input_timeout\": 5,
    \"no_input_agent_id\": \"$COMBINED_AGENT\"
  }" \
  | python3 -m json.tool

echo ""
echo "Done. Verify by calling +918035303580."
