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

echo "=== UI readability + RSS focus + Herman dashboard ==="

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/cockpit/static/css/tokens.css" \
  "$BASE/cockpit/static/css/pulse-theme.css" \
  "$HOST:$REMOTE/cockpit/static/css/"

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

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

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

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

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

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/migrations/012_rss_focus.sql" \
  "$HOST:$REMOTE/migrations/"

sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no "$HOST" bash <<'REMOTE'
set -e
cd ~/foodlinkk-command-center
docker exec -i foodlinkk_db psql -U aissa -d foodlinkk < migrations/012_rss_focus.sql
docker compose build tools-api cockpit
docker compose up -d tools-api cockpit
sleep 8
curl -sf -X POST http://localhost:8700/retail/rss/refresh | head -c 400
echo ""
curl -sf -o /dev/null -w "dashboard: %{http_code}\n" http://localhost:8600/
curl -sf -o /dev/null -w "marketing: %{http_code}\n" http://localhost:8600/marketing
curl -sf http://localhost:8700/retail/rss/live?limit=5 | head -c 300
echo ""
REMOTE

sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no aissa@10.4.7.19 \
  'python3 ~/foodlinkk-ai/hermes/notify.py --team "UI upgrade live: betere leesbaarheid, RSS alleen kant-en-klaar/supermarkt (klikbare bronnen), Herman dashboard interactief met milestones + pulse effecten. http://10.4.7.18:8600/"'

echo "=== DONE ==="
