#!/usr/bin/env bash
# Rollback produção Desk → layout legado (index.legacy.html)

set -euo pipefail

HOST="${1:-root@10.10.10.122}"
PASS="${DESK_SSH_PASS:-805353}"
CONTAINER="ligbox-ops-platform_frontend_1"
ROOT="$(cd "$(dirname "$0")/../../projects/ops-desk/frontend" && pwd)"

echo "==> ROLLBACK Desk produção → legacy"

sshpass -p "${PASS}" ssh -o StrictHostKeyChecking=no "${HOST}" "mkdir -p /tmp/desk-prod-rollback"

sshpass -p "${PASS}" scp -o StrictHostKeyChecking=no \
  "${ROOT}/index.legacy.html" \
  "${ROOT}/assets/app.legacy.js" \
  "${HOST}:/tmp/desk-prod-rollback/"

sshpass -p "${PASS}" ssh -o StrictHostKeyChecking=no "${HOST}" bash -s <<EOF
set -e
C=${CONTAINER}
docker cp /tmp/desk-prod-rollback/index.legacy.html \$C:/usr/share/nginx/html/index.html
docker cp /tmp/desk-prod-rollback/app.legacy.js \$C:/usr/share/nginx/html/assets/app.js
echo "Rollback aplicado — hard refresh no browser"
EOF
