#!/bin/bash
# Deploy viewer bot to ~/viewer
# Run from anywhere: ~/dev/scripts/deploy_viewer.sh

set -e

SRC_DIR="/home/videobot/dev"
DEST_DIR="/home/videobot/viewer"

echo "Deploying viewer bot to $DEST_DIR..."

# Copy viewer bot files
cp "$SRC_DIR/viewer/viewer_bot.py" "$DEST_DIR/"
cp "$SRC_DIR/viewer/data_reader.py" "$DEST_DIR/"
cp "$SRC_DIR/viewer/search.py" "$DEST_DIR/"
cp "$SRC_DIR/viewer/session.py" "$DEST_DIR/"

# Copy shared modules (database, token_manager, survey)
cp "$SRC_DIR/scripts/database.py" "$DEST_DIR/"
cp "$SRC_DIR/scripts/token_manager.py" "$DEST_DIR/"
cp "$SRC_DIR/scripts/survey_db.py" "$DEST_DIR/"
cp "$SRC_DIR/scripts/survey_handler.py" "$DEST_DIR/"

echo "Files copied:"
ls -la "$DEST_DIR"/*.py

# Restart service if running
if systemctl --user is-active --quiet viewer-bot 2>/dev/null; then
    echo ""
    echo "Restarting viewer-bot service..."
    systemctl --user restart viewer-bot
    sleep 2
    systemctl --user status viewer-bot --no-pager
else
    echo ""
    echo "viewer-bot service not running. Start with:"
    echo "  systemctl --user start viewer-bot"
fi

echo ""
echo "Done!"
