#!/usr/bin/env bash
set -euo pipefail

echo "Rolling back NOFX stack..."
# Stop frontend first to avoid serving partial content
if docker compose ps | grep -q nofx-frontend; then
  docker compose stop nofx-frontend || true
fi
# Recreate backend from previous image (assuming prior image cached)
if docker images | grep -q nofx-trading; then
  echo "Recreating backend from previous image..."
  docker compose rm -sf nofx
  docker compose up -d nofx
fi

echo "Restarting frontend..."
docker compose up -d nofx-frontend

echo "Stack status:"
docker compose ps