#!/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}

FILENAME="cypress.env.json"
FILEPATH=""

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

      echo "No data found for ${FILENAME}, check aws access (see generator script in readme)"
      exit 1
    fi
else
    echo "${FILEPATH}${FILENAME} exists."
fi
