#!/bin/bash
set -o pipefail

type=$1
region=$2
shift 2

case $type in
  country)
    output=$(aws ssm get-parameters-by-path \
      --region us-east-1 \
      --path /aws/service/global-infrastructure/regions/$region \
      --query 'Parameters[?Name.contains(@,`geolocationCountry`)].Value' \
      --output text \
      "$@")
    ;;
  full-name)
    output=$(aws ssm get-parameters-by-path \
      --region $region \
      --path /aws/service/global-infrastructure/regions/$region \
      --query 'Parameters[?Name.contains(@,`longName`)].Value' \
      --output text \
      "$@")
    ;;
  *)
    echo "not supported arg type"
    exit 1
    ;;
esac

if test $? -ne 0; then
    echo "Failed to get $type"
    exit 1
fi
echo "$output"