#!/bin/bash

# Development Docker Compose Runner
# This script sets up and runs the complete application stack in development mode

set -e

echo "🛠️  Starting Developer Portfolio Tracker in Development Mode"
echo "============================================================"

# Build shared types first
echo "📦 Building shared types..."
npm run build --workspace=@portfolio/shared-types

# Build all services for development
echo "🔨 Building all services for development..."
docker-compose -f docker-compose.dev.yml build

# Start the complete application stack
echo "🚀 Starting all services with hot reload..."
docker-compose -f docker-compose.dev.yml up -d

# Wait for services to start
echo "⏳ Waiting for services to start..."
sleep 30

# Check service status
echo "📊 Checking service status..."
docker-compose -f docker-compose.dev.yml ps

echo ""
echo "✅ Development environment started successfully!"
echo ""
echo "🌐 Access points:"
echo "   Frontend (Vite):     http://localhost:5173"
echo "   API Gateway:         http://localhost:3000"
echo "   User Service:        http://localhost:3001"
echo "   Task Service:        http://localhost:3002"
echo "   Analytics Service:   http://localhost:3003"
echo "   Diagram Service:     http://localhost:3004"
echo ""
echo "🛠️  Development Tools:"
echo "   Kafka UI:            http://localhost:8080"
echo "   Redis Commander:     http://localhost:8081"
echo "   Mongo Express:       http://localhost:8082"
echo "   phpMyAdmin:          http://localhost:8083"
echo ""
echo "🗄️  Database Connections:"
echo "   MySQL:               localhost:3306 (root/password)"
echo "   MongoDB:             localhost:27017 (admin/admin123)"
echo "   Redis:               localhost:6379"
echo "   Kafka:               localhost:9092"
echo ""
echo "📊 To view logs:"
echo "   docker-compose -f docker-compose.dev.yml logs -f [service-name]"
echo ""
echo "🛑 To stop all services:"
echo "   docker-compose -f docker-compose.dev.yml down"
echo ""
echo "🔄 To rebuild and restart a service:"
echo "   docker-compose -f docker-compose.dev.yml up -d --build [service-name]"