#!/usr/bin/env bash
set -euo pipefail

# Dev mode for sx-pub (SX-based ActivityPub)
# Bind-mounted source + auto-reload on externalnet
# Browse to pub.sx-web.org
#
# Usage:
#   ./dev-pub.sh              # Start sx-pub dev
#   ./dev-pub.sh down         # Stop
#   ./dev-pub.sh logs         # Tail logs
#   ./dev-pub.sh --build      # Rebuild image then start

COMPOSE="docker compose -p sx-pub -f docker-compose.dev-pub.yml"

case "${1:-up}" in
  down)
    $COMPOSE down
    ;;
  logs)
    $COMPOSE logs -f sx_pub
    ;;
  *)
    BUILD_FLAG=""
    if [[ "${1:-}" == "--build" ]]; then
      BUILD_FLAG="--build"
    fi
    $COMPOSE up $BUILD_FLAG
    ;;
esac
