#!/bin/bash

# Set up Maestro test environment with user account and robot pairing.
# After testing, pairing can be deleted with teardown_pairing.sh.
#
# Usage:
#   $ source test_env_setup.sh <maestro_env> <user_email> <first_name> <last_name> <robot_id>
#
# $1 - Maestro environment to be used for testing.
#      Supported environments:
#      ECS: ecs-dev, ecs-alpha, ecs-stage, ecs-beta
#      EKS: maestro-dev, maestro-staging, maestro-prod, maestro-<dev_ephemeral_env>
# $2 - User email to be created in Maestro.
# $3 - User first name.
# $4 - User last name.
# $5 - Robot ID to be paired with.
#
# Examples
#
#   $ source test_env_setup.sh maestro-dev esse@zoox.com Jesse Levinson kitt_12
#
# System variables set after the script completes:
#
# $bearer - Bearer auth token after user logged in.
# $MAESTRO_PAIRING_ID - Pairing ID between the user and the robot.

MAESTRO_ENV=$1
USER_EMAIL=$2
FIRST_NAME=$3
LAST_NAME=$4
ROBOT_ID=$5
SCRIPT_DIR=`git rev-parse --show-toplevel`/dispatch/scripts/env_setup

source $SCRIPT_DIR/set_gateway_urls.sh $MAESTRO_ENV

if [ $? -ne 0 ]
then
    return $?
fi

source $SCRIPT_DIR/create_user_and_login.sh $USER_EMAIL $FIRST_NAME $LAST_NAME

if [ $? -ne 0 ]
then
    return $?
fi

source $SCRIPT_DIR/pair_user_robot.sh $USER_EMAIL $ROBOT_ID

echo Done.
