#!/bin/bash

if [ -z "${AUTOMATION_USER_JWT}" ]; then
  echo "Error: AUTOMATION_USER_JWT variable is not defined."
  exit 1
fi

# get a random room
response=$(curl -sL --fail GET http://localhost:8134/chaturbate/random-room)
exitcode=$?
url=$(echo $response | jq -r '.url')
if [[ $exitcode -ne 0 || -z "$response" || -z "$url" ]]; then
  echo "failed to get random room. exitcode=${exitcode}, response=${response}, url=${url}"
  exit $exitcode
fi
echo "Random online chaturbate room url=${url}"



# create a recording
curl -sL -H "Authorization: Bearer ${AUTOMATION_USER_JWT}" \
     -H "Content-Type: application/json" \
     -d '{"url": "'"${url}"'"}' \
     http://localhost:9000/recordings
echo "recording created"