#!/bin/bash
# Do not bother modifying the prompt when we are not running in an AWS context - none of these variables will be configured
if [[ -n $AWS_CONTAINER_CREDENTIALS_RELATIVE_URI ]]; then

	[[ -n $ENCLOUD_CONTAINER_NAME ]] && CNAME="[$ENCLOUD_CONTAINER_NAME]"
	[[ -n $INFRA_PARAMETER_NAMESPACE ]] && INAME="-${INFRA_PARAMETER_NAMESPACE##*/}"
	[[ -n $ENCLOUD_ENV_TYPE ]] && ETYPE=$ENCLOUD_ENV_TYPE

	if [[ -z $CNAME || -z $INAME || -z $ETYPE ]]; then
		echo -e "$(tput setaf 3)WARNING$(tput sgr0): Missing environment variables, skipping PS1 configuration \n"
	else
		if [[ -z "$TERM" || "$TERM" == 'dumb' ]]; then
		    PS1="[\u@WS/ENCloud${INAME}/ECS \W]\\$ "
		else
		    # Set the prompt colour by environment type
		    case "${ETYPE}" in
			Dev)     _PROMPT_FG_COLOR=2 ;; # Green
			Test)    _PROMPT_FG_COLOR=4 ;; # Blue
			Stage)   _PROMPT_FG_COLOR=6 ;; # Cyan
			PreProd) _PROMPT_FG_COLOR=6 ;; # Cyan
			Prod)    _PROMPT_FG_COLOR=1 ;; # Red
			*)       _PROMPT_FG_COLOR=0 ;; # Black/White (Default FG)
		    esac
		    PS1="\[$(tput bold )\][\[$(tput sgr0)$(tput setaf $_PROMPT_FG_COLOR)\]\u@ENCloud${INAME}/ECS$CNAME \W\[$(tput sgr0)$(tput bold)\]]\\$ \[$(tput sgr0)\]"
		fi
	fi

fi
