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

echo "=== CEO Market + Retail Filters + Agent Avatars ==="

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/migrations/014_market_regulation_avatars.sql" "$HOST:$R/migrations/"

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/tools-api/app/connectors/market_stocks.py" \
  "$BASE/tools-api/app/connectors/rss_feeds.py" \
  "$BASE/tools-api/app/retail_360_routes.py" \
  "$HOST:$R/tools-api/app/connectors/" 2>/dev/null || true

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

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

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

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

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

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

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/cockpit/static/css/herman-dashboard.css" \
  "$BASE/cockpit/static/retail.css" \
  "$HOST:$R/cockpit/static/css/" 2>/dev/null || true

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

sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  "$BASE/cockpit/static/retail.css" "$HOST:$R/cockpit/static/"

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/014_market_regulation_avatars.sql

docker compose build tools-api cockpit
docker compose up -d tools-api cockpit
sleep 10

curl -sf -o /dev/null -w "dashboard: %{http_code}\n" http://localhost:8600/
curl -sf -o /dev/null -w "retail: %{http_code}\n" http://localhost:8600/retail
curl -sf -o /dev/null -w "agents: %{http_code}\n" http://localhost:8600/agents
curl -sf http://localhost:8700/retail/market/stocks | head -c 200
echo ""
curl -sf -X POST http://localhost:8700/retail/rss/refresh | head -c 150
echo ""
REMOTE

sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no aissa@10.4.7.19 \
  'python3 ~/foodlinkk-ai/hermes/notify.py --team "CEO dashboard upgrade: supermarkt beurs KPIs met neo equalizers, food markt highlights, CBS+regelgeving feeds. Retail 360 uitgebreide filters. Agents tab met animated avatars. Hard refresh Ctrl+Shift+R → http://10.4.7.18:8600/"'

echo DONE
