#!/bin/bash

AXIOM_PATH="$HOME/.axiom"
source "$AXIOM_PATH/interact/includes/vars.sh"
source "$AXIOM_PATH/interact/includes/functions.sh"

if [ "$1" == "ls" ]
then
    list_regions
elif [ "$1" == "select" ]
then
	region_json=$(regions)
	lines=$(echo $region_json | grep "$2" | wc -l | awk '{ print $1 }')
	
	if [ "$lines" -gt 0 ]
	then
		echo -e "${BWhite}Selected region $2${Color_Off}"
		cat $AXIOM_PATH/axiom.json | jq -r ".region=\"$2\"" | jq -r > $AXIOM_PATH/axiom.json.new
        mv $AXIOM_PATH/axiom.json.new $AXIOM_PATH/axiom.json
	fi
else
	echo "Usage:"
	echo -e "\taxiom-region ls - List available regions"
	echo -e "\taxiom-region select <nyc3> - Select region"
fi
