#!/usr/bin/env bash

# Configure the script to exit when a command fails.
set -e

: ${SCRIPTS_ROOT:="$(dirname $0)"/../../scripts}
export SCRIPTS_ROOT
source "${SCRIPTS_ROOT:?}"/util.sh

LOCAL_RUN_DIR="${REPOSITORY_ROOT:?}"/local-run
SELF_SCRIPTS="${LOCAL_RUN_DIR:?}"/scripts
source "${SELF_SCRIPTS:?}"/constants.sh

source "${SELF_SCRIPTS:?}"/scenario-files.sh
source "${SELF_SCRIPTS:?}"/scenario-files-fallback.sh
source "${SCENARIO_CONSTANTS_FILE:?}"
source "${SELF_SCRIPTS:?}"/compose-exports.sh

edo docker compose -f "${COMPOSE_FILE:?}" stop

if [ -f "${EPHEMERAL_SCENARIOS_FILE:?}" ]; then
	while IFS= read -r scenario_name; do
		if [[ -n "${scenario_name-}" ]]; then
			log_as_trace_ task local:scenarios:delete -y -- "${scenario_name:?}"
		fi
	done < "${EPHEMERAL_SCENARIOS_FILE:?}"
fi
