#!/bin/bash

# This script runs the test client using AWS credentials from environment variables

# Check if AWS credentials are exported
if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
  echo "⚠️  Warning: AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY environment variables are not set."
  echo "   The test client may not be able to connect to AWS services."
  
  # Check for AWS CLI
  if command -v aws &> /dev/null; then
    echo "ℹ️  AWS CLI is installed. You might want to get credentials using:"
    echo "   eval \$(aws configure export-credentials)"
    echo "   # OR for specific profile:"
    echo "   eval \$(aws configure export-credentials --profile your-profile)"
  fi
fi

# Display current AWS environment
echo ""
echo "Current AWS configuration:"
echo "AWS_REGION=${AWS_REGION:-us-east-1}"
echo "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID:0:5}... (${#AWS_ACCESS_KEY_ID} characters)"
echo "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY:0:5}... (${#AWS_SECRET_ACCESS_KEY} characters)"
if [ ! -z "$AWS_SESSION_TOKEN" ]; then
  echo "AWS_SESSION_TOKEN is set (${#AWS_SESSION_TOKEN} characters)"
fi
echo ""

# Run the client with AWS credentials properly passed
AWS_REGION=${AWS_REGION:-us-east-1} \
  pnpm start