#!/bin/bash
# Setup script for RPC Translator Service

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"

echo "Setting up RPC Translator Service..."

# Check if pnpm is installed
if ! command -v pnpm &> /dev/null; then
    echo "pnpm is not installed. Installing pnpm..."
    npm install -g pnpm
fi

# Install dependencies
echo "Installing dependencies with pnpm..."
cd "$PROJECT_DIR"
pnpm install

# Create .env file from template if it doesn't exist
if [ ! -f "$PROJECT_DIR/.env" ]; then
    echo "Creating .env file from template..."
    cp "$PROJECT_DIR/env.template" "$PROJECT_DIR/.env"
    echo "Please edit .env file and configure the required values."
else
    echo ".env file already exists, skipping..."
fi

# Build the project
echo "Building TypeScript..."
pnpm run build

echo ""
echo "Setup complete!"
echo ""
echo "Next steps:"
echo "1. Edit .env file with your configuration"
echo "2. Run 'pnpm run dev' for development"
echo "3. Run 'pnpm start' for production"
echo ""
