#!/usr/bin/env bash
# Build a product PDF from its LaTeX source and deploy it to the delivery folder.
# Usage:  bash resources/products/build.sh <slug> <Delivered-File-Name.pdf>
# Example: bash resources/products/build.sh ai-prompt-vault AI-Prompt-Vault.pdf
#
# Notes:
# - Engine: tectonic (XeTeX). Installed via `choco install tectonic`.
# - The bundled tectonic 0.3.2 default package URL is dead (archive.org 404),
#   so we MUST pass a working bundle mirror via --web-bundle.
# - Verified LaTeX recipe (see ai-prompt-vault/vault.tex): plain XeTeX (NO
#   fontspec/fontenc/lmodern) for correct German prose unicode, fancyvrb's
#   Verbatim for code/prompts (literal < > & % [ ]), tcolorbox + tikz for design.
set -euo pipefail

SLUG="${1:?slug required}"
OUTNAME="${2:?output pdf name required}"
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
SRCDIR="$ROOT/resources/products/$SLUG"
DEST="$ROOT/public/pay/_private/files/$OUTNAME"
BUNDLE="https://relay.fullyjustified.net/default_bundle.tar"

export PATH="$PATH:/c/ProgramData/chocolatey/bin"

cd "$SRCDIR"
tectonic --web-bundle "$BUNDLE" vault.tex
cp vault.pdf "$DEST"
echo "Deployed $SLUG -> $DEST"
