if [ -z "$1" ]; then
    echo "Usage: source get-cypress-vars.sh RELEASE_NAME"
    return 1
else
    release="$1"
fi

tempfile=$(mktemp)

helm -n stackspin-apps get values "$release" -o json > "$tempfile"

# Uncomment and add SSO details
# if you want to use OIDC-based login in your tests
# export CYPRESS_USE_SSO_LOGIN=true
# export CYPRESS_SSO_USER=admin@example.com
# export CYPRESS_SSO_PW=""

# Nextcloud admin username
export CYPRESS_NEXTCLOUD_ADMIN_USER=admin

# Nextcloud admin password imported from the helm values.
export CYPRESS_NEXTCLOUD_ADMIN_PW=$(jq -r '.nextcloud.nextcloud.password' < "$tempfile")

export CYPRESS_BASE_URL="https://$(jq -r '.nextcloud.nextcloud.host' < "$tempfile")"

export CYPRESS_ONLYOFFICE_URL=$(jq -r '.onlyoffice.server_name' < "$tempfile")

# Comma-separated list of applications to test. Check if the cypress
# tests supports testing your application if you want to add apps here.
export INSTALLED_APPS=""

rm "$tempfile"

echo "Imported values from Helm."
