#!/bin/bash
# Build all applications

set -e

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

echo "Building all applications..."

cd "$PROJECT_ROOT"

# Build backend services
echo "Building backend services..."
cd backend

# Indexer
echo "  Building indexer..."
go build -o /usr/local/bin/explorer-indexer ./indexer/main.go

# API
echo "  Building API..."
go build -o /usr/local/bin/explorer-api ./api/rest/main.go

# Gateway
echo "  Building gateway..."
go build -o /usr/local/bin/explorer-gateway ./api/gateway/main.go

# Search
echo "  Building search service..."
go build -o /usr/local/bin/explorer-search ./api/search/main.go

# Build frontend
echo "Building frontend..."
cd ../frontend
npm ci
npm run build

echo ""
echo "All applications built successfully!"
echo ""
echo "Binaries installed to:"
echo "  /usr/local/bin/explorer-indexer"
echo "  /usr/local/bin/explorer-api"
echo "  /usr/local/bin/explorer-gateway"
echo "  /usr/local/bin/explorer-search"

