#!/bin/bash
set -e
HOST="aissa@10.4.7.18"
PASS='Foodlinkk#2026'
BASE="/tmp/foodlinkk-deploy"
R="~/foodlinkk-command-center"

echo "=== Beurs Live tab + food trends + platform events ==="

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/tools-api/app/connectors/market_stocks.py" \
  "$BASE/tools-api/app/connectors/food_trends.py" \
  "$HOST:$R/tools-api/app/connectors/"

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/tools-api/app/retail_360_routes.py" \
  "$HOST:$R/tools-api/app/"

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/cockpit/app/main.py" \
  "$BASE/cockpit/app/routes/beurs.py" \
  "$BASE/cockpit/app/routes/api.py" \
  "$BASE/cockpit/app/routes/retail.py" \
  "$BASE/cockpit/app/services/platform_live.py" \
  "$HOST:$R/cockpit/app/routes/" 2>/dev/null || true

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/cockpit/app/main.py" "$HOST:$R/cockpit/app/"

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/cockpit/app/routes/beurs.py" "$HOST:$R/cockpit/app/routes/"

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/cockpit/app/routes/api.py" \
  "$BASE/cockpit/app/routes/retail.py" \
  "$HOST:$R/cockpit/app/routes/"

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/cockpit/app/services/platform_live.py" "$HOST:$R/cockpit/app/services/"

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/cockpit/templates/beurs.html" \
  "$BASE/cockpit/templates/base.html" \
  "$BASE/cockpit/templates/dashboard.html" \
  "$BASE/cockpit/templates/marketing.html" \
  "$HOST:$R/cockpit/templates/"

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/cockpit/static/css/beurs.css" \
  "$BASE/cockpit/static/css/pulse-theme.css" \
  "$BASE/cockpit/static/css/herman-dashboard.css" \
  "$HOST:$R/cockpit/static/css/"

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/cockpit/static/js/beurs.js" \
  "$BASE/cockpit/static/js/briefing-charts.js" \
  "$HOST:$R/cockpit/static/js/"

sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no "$HOST" bash <<'REMOTE'
set -e
cd ~/foodlinkk-command-center
docker compose build tools-api cockpit
docker compose up -d tools-api cockpit
sleep 10
curl -sf -o /dev/null -w "beurs: %{http_code}\n" http://localhost:8600/beurs
curl -sf http://localhost:8700/retail/market/supermarkets | head -c 250
echo ""
curl -sf http://localhost:8600/api/live/platform?limit=3 | head -c 200
echo ""
REMOTE

sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no aissa@10.4.7.19 \
  'python3 ~/foodlinkk-ai/hermes/notify.py --team "Beurs Live tab: supermarkt aandelen (AH/Jumbo info), halal trends, concept lab, platform events monitor. http://10.4.7.18:8600/beurs — Ctrl+Shift+R"'

echo DONE
