#!/bin/bash
set -e

echo "🔧 Cleaning up old containers..."
cd backend
docker compose -f docker-compose.dev.yml down 2>/dev/null || true

echo "🗑️  Removing old image..."
docker rmi normogen-backend-dev 2>/dev/null || true

echo "🏗️  Building Docker image (this may take a few minutes)..."
docker compose -f docker-compose.dev.yml build --no-cache

echo "🚀 Starting services..."
docker compose -f docker-compose.dev.yml up -d

echo "⏳ Waiting for server to be ready..."
sleep 5

echo "📊 Container status:"
docker compose -f docker-compose.dev.yml ps

echo ""
echo "📋 Server logs (ctrl+c to exit):"
docker compose -f docker-compose.dev.yml logs -f backend
