#!/bin/bash
# Gera 60 imagens Visual Companion via Gemini 3 Pro Image.
# Tema: NXT/Anthropic dark + peach + cream.
#
# Uso: bash generate.sh [category]
#   Sem args: gera tudo (60 imagens, ~$2.40, ~10min)
#   Com category: só esse subset (tools, mcps, states, pickers, brand)

set -uo pipefail

KEY="${LITELLM_MASTER_KEY:-sk-a54f90771bee2461c3a5e6a73b5999c39b28e2d86228baebb550d3979dc5868f}"
ENDPOINT="http://127.0.0.1:4000/v1/images/generations"
DIR="/root/nxt/terminal.net.br/recursos/assets/visual-companion"
MODEL="gemini-3-pro-image"

# Tema visual master — todos os prompts injetam isto
THEME="dark background #141413, peach orange #D97757 accent, cream #F4F0E8 highlights, minimalist Anthropic-inspired aesthetic, clean geometric design, centered subject with padding, square 1:1 ratio, no text, no labels"

# Skip filter
ONLY="${1:-all}"

generate() {
    local category="$1"
    local name="$2"
    local description="$3"
    local outpath="$DIR/$category/$name.png"

    if [ -f "$outpath" ]; then
        echo "✓ exists: $category/$name.png"
        return
    fi

    if [ "$ONLY" != "all" ] && [ "$ONLY" != "$category" ]; then
        return
    fi

    local prompt="${description}, ${THEME}"
    echo "→ generating: $category/$name.png"

    response=$(curl -sS --max-time 60 -X POST "$ENDPOINT" \
        -H "Authorization: Bearer $KEY" \
        -H "Content-Type: application/json" \
        -d "$(jq -nc --arg model "$MODEL" --arg prompt "$prompt" \
            '{model:$model,prompt:$prompt,n:1,size:"1024x1024",response_format:"b64_json"}')")

    b64=$(echo "$response" | jq -r '.data[0].b64_json // empty')
    if [ -z "$b64" ]; then
        echo "✗ FAIL: $name → $(echo $response | head -c 200)"
        return 1
    fi

    echo "$b64" | base64 -d > "$outpath"
    local sz=$(stat -c%s "$outpath" 2>/dev/null)
    if [ "$sz" -lt 5000 ]; then
        echo "✗ too small ($sz bytes), retrying..."
        rm "$outpath"
        return 1
    fi
    echo "✓ saved: $outpath ($sz bytes)"
    sleep 0.5  # rate limit gentle
}

# === TOOLS (10) ===
generate tools bash "a sleek terminal icon with command prompt cursor, geometric and modern"
generate tools read "an open document with a stylized eye reading it"
generate tools edit "a fountain pen tip writing inside curly braces"
generate tools write "a feather quill creating a new file with a star/sparkle"
generate tools grep "a magnifying glass over a grid of code lines"
generate tools glob "an asterisk wildcard symbol over a file tree structure"
generate tools task "a robot agent silhouette delegating to a mini-bot"
generate tools webfetch "a globe with a download arrow pointing inward"
generate tools websearch "a magnifying glass examining a globe"
generate tools notebookedit "a Jupyter notebook icon with code cells"

# === STATES (11) ===
generate states thinking "a stylized brain with subtle glow and dotted spinner pattern"
generate states working "hands typing on a keyboard with motion blur"
generate states done "a clean checkmark inside a circle, success energy"
generate states error "a warning triangle with subtle electric glow"
generate states question "a speech bubble with question mark, friendly"
generate states waiting "an hourglass with sand falling, patient calm"
generate states success "a celebration burst with sparkles and check"
generate states searching "a magnifying glass with motion lines, active scanning"
generate states compiling "interlocking gears rotating, machinery activity"
generate states deploying "a stylized rocket launching upward with trail"
generate states paused "a pause icon two vertical bars, calm rest state"

# === BRAND (4) ===
generate brand nxt "the letters NXT abstract logo, futuristic geometric"
generate brand anthropic "the Anthropic A symbol clean and authoritative"
generate brand claude "the Claude asterisk symbol elegant and centered"
generate brand welcome "Clawde mascot character waving hello, peach + cream"

# === PICKERS (12) — plugin nxt-cockpit ===
generate pickers skills "a lightbulb opening to reveal a book, knowledge"
generate pickers mcps "interconnected cables forming a network node"
generate pickers agents "a group of robot silhouettes working together"
generate pickers plugins "a power plug and electrical socket connecting"
generate pickers hooks "a metal hook on a chain, automation trigger"
generate pickers marketplaces "a futuristic shop facade with goods"
generate pickers essential "a star symbol with outline, premium pick"
generate pickers output-style "a paint palette with brushes, customization"
generate pickers sessions "a folder with multiple file tabs"
generate pickers whatsapp "a green chat bubble with phone icon, messaging"
generate pickers worktree "a stylized git tree branching, versions"
generate pickers context "a treasure chest opening with subtle glow"

# === MCPs (23) ===
generate mcps pilot "a friendly aircraft pilot helmet with NXT branding"
generate mcps chrome-devtools "the Chrome browser logo with developer tools wrench"
generate mcps surrealdb "an abstract surreal database geometric pattern"
generate mcps litellm "a cable management hub with multiple connectors"
generate mcps context7 "the number 7 stylized with documentation lines"
generate mcps tavily "a search engine T monogram, modern"
generate mcps exa "the letter E with search rays emanating"
generate mcps figma-mcp "the Figma design tool F logo geometric"
generate mcps shadcn "a slash forward design symbol minimalist"
generate mcps iconify "a grid of small icons abstract"
generate mcps repomix "a stylized repo box with code symbols"
generate mcps nuvem-fiscal "a cloud with Brazilian tax document"
generate mcps replicate "an infinity loop replication symbol"
generate mcps fal "the lowercase letters fal artistic"
generate mcps sendgrid "a paper plane with grid pattern email"
generate mcps perplexity "a brain with question marks orbiting"
generate mcps magicui "a magic wand with sparkles UI elements"
generate mcps daisyui "a daisy flower geometric stylized"
generate mcps cnpjota "letters CNPJ stylized Brazilian business document"
generate mcps bcb "Brazilian Central Bank coin with R\$ symbol"
generate mcps ibge "Brazilian map outline with statistics overlay"
generate mcps brasil-api "Brazilian flag colors abstracted with API symbols"
generate mcps nfse "Brazilian tax invoice document stylized"

echo
echo "========================================="
echo "Visual Companion generation complete."
echo "========================================="
ls -1 "$DIR"/{tools,states,brand,pickers,mcps}/*.png 2>/dev/null | wc -l
echo "images saved in $DIR"
