#!/bin/bash 

shopt -s extglob

# putting settings in an array allows unescaped newlines in definition
# also sorted to make it easier to find things.
settings=(
  -b:v 3000k
  -bf 2
  -c:v libx264
  -level 3.1
  -movflags faststart
  -pix_fmt yuv420p
  -preset:v slow
  -profile:v Main
  -r 29.97
  -s 1280x720
  -threads 0
  -vf yadif=0:-1
)


FORCE_REFRESH=${1:-false}

files=( "cypress.env.json" )
paths=( "" )

  if [ ! -f "${paths[$i]}${files[$i]}" ] || $FORCE_REFRESH ]; then
      echo "downloading ${files[$i]} from secrets manager"
      aws secretsmanager get-secret-value --secret-id qa/cypress-configs/${files[$i]} --region us-east-1 --query SecretString --output text > ${paths[$i]}${files[$i]};
      if [ ! -s "${paths[$i]}"${files[$i]} ]; then
        rm "${paths[$i]}""${files[$i]}"

        echo "No data found for ${files[$i]}, check aws access (see generator script in readme)"
        exit 1
      fi
  else echo "${paths[$i]}${files[$i]} exists."
  fi


