#!/usr/bin/env bash
#clear
#export PS4='\e[90m+${LINENO} in ${#BASH_SOURCE[@]}>${FUNCNAME[0]}:${BASH_SOURCE[@]##*/} \e[0m'
#set -x

#echo "starting: $0 <LOG_LEVEL=$1>"



map.usage()
{
  local this=${0##*/}
  echo "You started 
$0

  Usage:
  $this: command   description and Parameter

      usage     prints this dialog while it will print the status when there are no parameters          
      v         print version information
      init      initializes ...nothing yet
  
  Examples
    $this v
    $this create mapName ENV_PREFIX entryName
    $this load name <?path>
    $this save name <?path>

    $this select key
    $this set key NAME value
 
  "
}

map.create()
{
  local mapName=$1
  shift
  local prefix=$1
  shift
  local entryName=$1
  shift
  
  let i=${#MAPS[@]}
  MAPS[i]=$mapName
  MAP_PREFIX[i]=$mapName

  eval ${prefix}_MAP_KEY[0]=$entryName
  CURRENT_MAP=${prefix}_MAP_KEY
  #map.save $mapName.map .
  echo new map ${CURRENT_MAP} with name ${!CURRENT_MAP[0]}
  echo len of ${CURRENT_MAP}: ${#!CURRENT_MAP[@]}
}

map.save()
{
  local mapName=$1
  shift
  local folder=$1
  shift

  if [ -z "$folder" ]; then
    folder=$(pwd)
  fi
  {
    for (( i=0; $i < "${#!CURRENT_MAP[@]}"; i+=1 )); do
      echo  SCENARIO_MAP_KEYS[$i]=${SCENARIO_MAP_KEYS[$i]}
      echo  SCENARIO_MAP_VERSION[$i]=${SCENARIO_MAP_VERSION[$i]}
      echo  SCENARIO_MAP_DC_NAME[$i]=${SCENARIO_MAP_DC_NAME[$i]}
      echo  SCENARIO_MAP_DI_NAME[$i]=${SCENARIO_MAP_DI_NAME[$i]}
      echo  SCENARIO_MAP_VALUES[$i]=${SCENARIO_MAP_VALUES[$i]}
      echo  SCENARIO_MAP_BACKUP[$i]=${SCENARIO_MAP_BACKUP[$i]}
      echo
    done 
  } >${mapName}.map
}

map.start()
{
  #echo "sourcing init"
  source this

  # if [ -z "$1" ]; then
  #   status.discover "$@"
  #   return 0
  # fi

  this.start "$@"
}

map.start "$@"

