#!/bin/bash

API_URL="http://localhost:8000"

# Create a new configuration and store the UUID
CONFIG_ID=$(curl -s -X POST "$API_URL/config" | jq -r '.config_id')
echo "Created new configuration with ID: $CONFIG_ID"

# Update multiple params at once
curl -X PUT "$API_URL/config/$CONFIG_ID/params" -H "Content-Type: application/json" -d '[
  {"name": "post_prompt_url", "value": "http://user:pass@some.server.com/rest/post.cgi"},
  {"name": "direction", "value": "inbound"},
  {"name": "wait_for_user", "value": true},
  {"name": "end_of_speech_timeout", "value": 2000},
  {"name": "attention_timeout", "value": 10000},
  {"name": "inactivity_timeout", "value": 600000}
]'

# Update prompt
curl -X PUT "$API_URL/config/$CONFIG_ID/prompt" -H "Content-Type: application/json" -d '{
  "confidence": 0.6,
  "barge_confidence": 0.1,
  "top_p": 1.0,
  "temperature": 0.3,
  "frequency_penalty": 0.1,
  "presence_penalty": 0.1,
  "text": "You name is Franklin and you are an expert at Star Wars. Introduce yourself and see if I have any questions."
}'

# Update post-prompt
curl -X PUT "$API_URL/config/$CONFIG_ID/post_prompt" -H "Content-Type: application/json" -d '{
  "confidence": 0.6,
  "barge_confidence": 0.1,
  "top_p": 1.0,
  "temperature": 0.3,
  "frequency_penalty": 0.0,
  "presence_penalty": 0.0,
  "text": "Please summarize the conversation"
}'

# Update languages
curl -X PUT "$API_URL/config/$CONFIG_ID/languages" -H "Content-Type: application/json" -d '[
  {"name": "English", "code": "en-US", "voice": "en-US-Neural2-F"},
  {"name": "French", "code": "fr-FR", "voice": "fr-FR-Neural2-E"}
]'

# Update hints
curl -X PUT "$API_URL/config/$CONFIG_ID/hints" -H "Content-Type: application/json" -d '["testing", "hints"]'

# Add/Update SWAIG function
curl -X PUT "$API_URL/config/$CONFIG_ID/swaig/functions/get_weather" -H "Content-Type: application/json" -d '{
  "function": "get_weather",
  "meta_data_token": "5dcec27c-107b-11ee-a281-62c3bdb19a89",
  "meta_data": {"my_key": "some value"},
  "purpose": "To determine what the current weather is in a provided location.",
  "argument": {
    "type": "object",
    "properties": {
      "location": {
        "type": "string",
        "description": "the location to check the weather in"
      }
    }
  }
}'