#!/usr/bin/env bash

set -euo pipefail

ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT_DIR"

STEP_BY_STEP=0
VERBOSE=0
RESET=0

while [[ $# -gt 0 ]]; do
  case "$1" in
    --reset)
      RESET=1
      shift
      ;;
    --step-by-step|-i)
      STEP_BY_STEP=1
      VERBOSE=1
      shift
      ;;
    --verbose|-v)
      VERBOSE=1
      shift
      ;;
    *)
      printf 'usage: %s [--reset] [--step-by-step|-i] [--verbose|-v]\n' "$0" >&2
      exit 1
      ;;
  esac
done

if [[ -f "$ROOT_DIR/.env" ]]; then
  set -a
  # shellcheck disable=SC1091
  source "$ROOT_DIR/.env"
  set +a
fi

export RHO_PI_AUTH_JSON="${RHO_PI_AUTH_JSON:-/Users/madhavajay/.pi/agent/auth.json}"

ARGS=()
if (( STEP_BY_STEP )); then
  ARGS+=(--step-by-step)
fi
if (( VERBOSE )); then
  ARGS+=(--verbose)
fi
if (( RESET )); then
  ARGS+=(--reset)
fi

exec python3 "$ROOT_DIR/tests/run_yaml_scenario.py" \
  "${ARGS[@]}" \
  "$ROOT_DIR/tests/scenarios/two-console-demo-agent/scenario.yaml"
