#!/bin/sh
# rustelo-content — content authoring CLI (local installation wrapper)
#
# Dispatches subcommands to the installed Nushell authoring scripts under
# $RUSTELO_CONTENT_HOME (default ~/.local/share/rustelo-content). Installed at
# $HOME/.local/bin/rustelo-content by `just content-install`.
#
# A POSIX sh dispatcher (not nu) so arbitrary downstream flags forward verbatim
# through "$@" without Nushell's custom-command flag parsing intercepting them.
#
# The underlying scripts default their paths to ./site/content, ./site/public
# and ./site/config/image-generation.ncl, so run from a site workspace root
# (the dir containing site/), exactly like content_processor.
set -eu

SHARE="${RUSTELO_CONTENT_HOME:-$HOME/.local/share/rustelo-content}"

usage() {
    cat <<EOF
rustelo-content — content authoring toolkit

usage: rustelo-content <command> [args...]

commands:
  images        Generate AI images for content (provider-agnostic: openai|gemini)
  sync          Translation parity (validate-translations | generate-missing | ...)
  validate      Validate content consistency
  validate-ids  Validate cross-language id consistency
  new           Scaffold a new content item (blog|recipes|projects|activities)
  copy-images   Copy _images/ into the public assets tree

  Run 'rustelo-content <command> --help' for command-specific flags.

env:
  RUSTELO_CONTENT_HOME   script home (default: ~/.local/share/rustelo-content)
  OPENAI_API_KEY         required for 'images' when provider=openai
  GEMINI_API_KEY         required for 'images' when provider=gemini
EOF
}

cmd="${1:-}"
[ $# -gt 0 ] && shift

case "$cmd" in
    images)        exec nu "$SHARE/generate-images.nu" "$@" ;;
    sync)          exec nu "$SHARE/sync-translations.nu" "$@" ;;
    validate)      exec nu "$SHARE/validate-content.nu" "$@" ;;
    validate-ids)  exec nu "$SHARE/review/validate-id-consistency.nu" "$@" ;;
    new)           exec nu "$SHARE/generate-content.nu" "$@" ;;
    copy-images)   exec nu "$SHARE/copy-content-images.nu" "$@" ;;
    ""|-h|--help|help) usage ;;
    *)
        printf 'rustelo-content: unknown command %s\n\n' "$cmd" >&2
        usage >&2
        exit 1 ;;
esac
