#!/bin/bash
# Sync appropriate files to tractatus-framework public repo

SRC="/home/theflow/projects/tractatus"
DEST="/home/theflow/projects/tractatus-public"

echo "=== Syncing tractatus -> tractatus-framework (public) ==="

# Core application files
echo "Copying package files..."
cp "$SRC/package.json" "$DEST/"
cp "$SRC/package-lock.json" "$DEST/"

# Source code
echo "Copying src/ directory..."
rsync -av --delete "$SRC/src/" "$DEST/src/"

# Tests
echo "Copying tests/ directory..."
rsync -av --delete "$SRC/tests/" "$DEST/tests/"

# Scripts (excluding sensitive ones)
echo "Copying scripts/ directory..."
mkdir -p "$DEST/scripts"
rsync -av "$SRC/scripts/" "$DEST/scripts/" \
  --exclude="*backup*" \
  --exclude="*.old" \
  --exclude="temp*"

# Public assets
echo "Copying public/ directory..."
rsync -av "$SRC/public/" "$DEST/public/" \
  --exclude="downloads/*.pdf" \
  --exclude="downloads/*.tar.gz"

# Systemd service files
echo "Copying systemd/ directory..."
rsync -av --delete "$SRC/systemd/" "$DEST/systemd/"

# Deployment quickstart
echo "Copying deployment-quickstart/ directory..."
rsync -av --delete "$SRC/deployment-quickstart/" "$DEST/deployment-quickstart/"

# Documentation - markdown
echo "Copying docs/markdown/..."
mkdir -p "$DEST/docs/markdown"
rsync -av --delete "$SRC/docs/markdown/" "$DEST/docs/markdown/"

# Documentation - API
echo "Copying docs/api/..."
mkdir -p "$DEST/docs/api"
rsync -av --delete "$SRC/docs/api/" "$DEST/docs/api/"

# Documentation - governance (PUBLIC ONLY)
echo "Copying docs/governance/ (public files only)..."
mkdir -p "$DEST/docs/governance"
cp "$SRC/docs/governance/TRA-VAL-0001-core-values-principles-v1-0.md" "$DEST/docs/governance/" 2>/dev/null || true
cp "$SRC/docs/governance/CODING_BEST_PRACTICES_SUMMARY.md" "$DEST/docs/governance/" 2>/dev/null || true

# Setup instructions
echo "Copying setup instructions..."
cp "$SRC/SETUP_INSTRUCTIONS.md" "$DEST/"

# .env.example (but NOT .env)
echo "Copying .env.example..."
cp "$SRC/.env.example" "$DEST/"

echo "=== Sync complete ==="
