#!/bin/bash
set -e

echo "🔧 Deploying Extrudex Docker runtime..."

# Check if Docker Compose is available
if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
    echo "❌ Docker Compose is not installed"
    exit 1
fi

COMPOSE_CMD="docker compose"
if command -v docker-compose &> /dev/null; then
    COMPOSE_CMD="docker-compose"
fi

echo "📦 Building and starting services..."
$COMPOSE_CMD -f docker-compose.dev.yml up -d --build

echo "⏳ Waiting for services to become healthy..."
sleep 15

echo "✅ Deployment complete!"
echo ""
echo "Services running:"
echo "  • PostgreSQL:    localhost:5433"
echo "  • Extrudex API: http://localhost:5080"
echo "  • Extrudex Web: http://localhost:5081"
echo ""
echo "To view logs:"
echo "  $COMPOSE_CMD -f docker-compose.dev.yml logs -f"
echo ""
echo "To stop:"
echo "  $COMPOSE_CMD -f docker-compose.dev.yml down"