#!/bin/bash
# deploy.sh - Deploy dgray.io to production server via rsync
#
# Usage:   ./deploy.sh [user@host] [remote-path]
# Example: ./deploy.sh admin@dgray.io /home/admin/web/dgray.io/public_html
#
# Prerequisites:
#   - SSH key authentication configured
#   - rsync installed locally and on server

set -e

# --- Configuration ---
REMOTE_USER_HOST="${1:-admin@dgray.io}"
REMOTE_PATH="${2:-/home/admin/web/dgray.io/public_html}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

# Files/directories to exclude from deployment
EXCLUDES=(
    ".git"
    ".gitignore"
    "AGENTS.md"
    "deploy.sh"
    "docs/"
    "tests/"
    "README.md"
    ".vscode"
    ".idea"
)

# --- Build exclude arguments ---
EXCLUDE_ARGS=""
for item in "${EXCLUDES[@]}"; do
    EXCLUDE_ARGS="$EXCLUDE_ARGS --exclude=$item"
done

# --- Deploy ---
echo "Deploying dgray.io"
echo "  From: $SCRIPT_DIR"
echo "  To:   $REMOTE_USER_HOST:$REMOTE_PATH"
echo ""

rsync -avz --delete \
    $EXCLUDE_ARGS \
    "$SCRIPT_DIR/" \
    "$REMOTE_USER_HOST:$REMOTE_PATH/"

echo ""
echo "Deploy complete."
