#!/bin/bash
# Development environment setup script

set -e

echo "🚀 Setting up development environment..."

# Check prerequisites
command -v docker >/dev/null 2>&1 || { echo "Docker is required but not installed. Aborting." >&2; exit 1; }
command -v docker-compose >/dev/null 2>&1 || { echo "Docker Compose is required but not installed. Aborting." >&2; exit 1; }
command -v pnpm >/dev/null 2>&1 || { echo "pnpm is required but not installed. Aborting." >&2; exit 1; }

# Start services
echo "Starting Docker services..."
docker-compose -f scripts/dev/docker-compose-dev.yml up -d

# Wait for services to be ready
echo "Waiting for services to be ready..."
sleep 10

# Check service health
echo "Checking service health..."
docker-compose -f scripts/dev/docker-compose-dev.yml ps

# Install dependencies
echo "Installing dependencies..."
pnpm install

# Run database migrations
echo "Running database migrations..."
pnpm --filter @the-order/database migrate

# Build packages
echo "Building packages..."
pnpm build

echo "✅ Development environment ready!"
echo ""
echo "Services available at:"
echo "  • PostgreSQL: localhost:5432"
echo "  • Redis: localhost:6379"
echo "  • OpenSearch: localhost:9200"
echo "  • OpenSearch Dashboards: http://localhost:5601"
echo "  • Prometheus: http://localhost:9090"
echo "  • Grafana: http://localhost:3000 (admin/admin)"
echo ""
echo "To start services: pnpm dev"

