#!/usr/bin/env bash

environment=$1

if [[ -z "$environment" ]]; then
    msg="missing required environment (one of 'dev', 'uat', or 'prod')"
    echo "$msg"
    exit 1
fi

# Remove the first argument from $@:
shift

# Get the first argument from the rest of the arguments (need this since it
# comes between "suite" and "suite-core-${environment}".
first_arg=$1

# Map the environment to its namespace and command.
case "$environment" in
    dev)
        namespace="openvox-dev"
        command="openvoxca-dev"
        ;;
    uat)
        namespace="openvox-uat"
        command="openvoxca-uat"
        ;;
    prod)
        namespace="openvox-prod"
        command="openvoxca-prod"
        ;;
    *)
        echo "invalid environment '$environment' (one of 'dev', 'uat', or 'prod')"
        exit 1
        ;;
esac

# Remove the first argument from $@:
shift

cmd="kremctl --cluster=openvox $command $first_arg $namespace -- $*"
echo "about to run command '$cmd'"

kremctl --cluster=openvox "$command" "$first_arg" "$namespace" -- $@
