# Set your activity_type (analytics_digest or spike_detector)
activity_type=analytics_digest

# Set your account_type (vendor or subaccount)
account_type=vendor

# Set your account_ids
account_ids=(1234 4567)

# Set your user_ids
user_ids=(oa:1234 oa:4567)

# Set your environment (qa or prod)
env=qa

# Set your endpoint (subscribe or unsubscribe)
endpoint=subscribe

url=https://${env}-ows-notifications.theorchard.io/${endpoint}

for account_id in ${account_ids[*]}
do
    for user_id in ${user_ids[*]}
    do
    read -d '' data << EOF
{
    "user_feed_name":"user_email_notifications",
    "feed_name":"label_${activity_type}",
    "feed_id":"${account_type}_${account_id}"
}
EOF
        resp=$(curl --write-out %{http_code} --silent --output /dev/null \
          --request POST \
          --header "Content-Type: application/json" \
          --header "Orchard-User-Id: ${user_id}" \
          --header "Grass-Account-Id: ${account_id}" \
          --header "Grass-Account-Type: ${account_type}" \
          --data "${data}" \
          ${url})

        if [ $resp -ne 200 ]; then
            echo "Could not ${endpoint} user ${user_id} to ${account_type}_${account_id} for ${activity_type}"
            exit 1
        fi
        echo "User ${user_id} ${endpoint}d to ${account_type}_${account_id} for ${activity_type}"
      done
done
