#!/usr/bin/env bash
# Real demos for P045 "Why Your Gemini API Free Tier Runs Out So Fast". Runs on the Mac (Docker Desktop): the key
# lives only on the Mac, never on render01.
# Everything goes to a throwaway Google Cloud project made for this video (ce-freetier-p045e): no billing account,
# so it only has the free tier and nothing in it can cost money, and it shares no quota with the keys our own
# pipeline uses (voice, reviews). Its one key ("Ana's key", restricted to the Gemini API) is read from
# ~/.ce-secrets/p045_key, never printed: the driver refuses to save any output that contains it.
# One container, ce-p045f-laptop: a stock Ubuntu 24.04 with curl, jq and Google's Gen AI SDK (lab/Dockerfile), Ana's
# shop scripts in ~/shop. Every command shown is typed into a real interactive bash in a pty (demo_driver.py).
# Off camera, the driver also reads the project's own free-tier limits from the Service Usage API with gcloud's
# login on the Mac (only the numbers are saved). Delete the project once the video is out:
#   gcloud projects delete ce-freetier-p045e
set -euo pipefail
cd "$(dirname "$0")"
export PROJECT=${PROJECT:-ce-freetier-p045e}
[ "$(gcloud billing projects describe "$PROJECT" --format='value(billingEnabled)')" = "False" ] ||
  { echo "the lab project must have no billing"; exit 1; }
P=ce-p045f
cleanup() { docker rm -f $P-laptop >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t $P-laptop lab >/dev/null
GEMINI_API_KEY=$(cat "${KEYFILE:-$HOME/.ce-secrets/p045_key}")
export GEMINI_API_KEY
docker run -d --name $P-laptop --hostname laptop -e GEMINI_API_KEY $P-laptop sleep infinity >/dev/null
python3 - "$P" < demo_driver.py
