#!/usr/bin/env bash
set -euo pipefail

wv_cluster=${WV_CLUSTER:-dev-aws}

if [ "$#" -lt 1 ]; then
    echo "Expected namespace argument"
    exit 1
else
    # use first positional arg to overide namespace for core envs if one is provided
    case "$1" in

    dev)
        wv_namespace=zrnwv-dev
        ;;

    staging)
        wv_namespace=zrnwv-staging
        ;;

    prod)
        wv_namespace=zrnwv-prod
        ;;
    zrnwv-*)
        wv_namespace=$1
        ;;

    *)
        ;;
    esac

fi

# double check the user wants to target prod
if [[ $wv_namespace = "zrnwv-prod" ]]; then
    read -r -p "Are you sure you want to target prod? [y/n] " response
    if ! [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
        exit 1
    fi
fi

echo "Selecting namespace $wv_namespace in cluster $wv_cluster"
# kubectl config use-context $wv_namespace
kubectl config set-context $wv_cluster --namespace=$wv_namespace
