#!/bin/bash
# NEONCYBER Batch Generator - 6 variations
# Usage: ./generate-batch.sh cityscape

set -e

COMFYUI="http://192.168.1.57:8188"
CATEGORY="${1:-cityscape}"
DATE=$(date +%Y-%m-%d)

echo "🎨 NEONCYBER Batch Generator - 6 Variations"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Category: $CATEGORY"
echo "Generating: 6 unique variations"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

# 6 different cityscape variations
PROMPTS=(
    # Variation 1: Classic empty street
    "Wide empty cyberpunk street at night, minimal anime style. Low camera angle down wet pavement with pink and cyan neon reflections. Purple vending machine left side, stacked neon signs right. Deep purple fog in distance. Rain bokeh, clean composition. Dark purple sky, obsidian pavement. Atmospheric depth, cinematic lighting. 1920x1080 widescreen, minimal design, masterpiece quality."

    # Variation 2: Alley with stairs
    "Narrow cyberpunk alley with wet stone stairs descending into purple haze, minimal anime aesthetic. Neon signs hang overhead - pink ramen shop left, cyan electronics right. Single street lamp casts purple glow. Empty, atmospheric solitude. Rain-slicked steps reflect colored light. Clean minimal composition with depth. Dark moody lighting, neon accents. 1920x1080 widescreen wallpaper, cinematic quality."

    # Variation 3: Train station platform
    "Empty cyberpunk train platform at night, minimal anime style. Wide shot with platform edge in lower third, purple neon train arriving from fog in distance. Pink warning lights reflect in wet platform floor. Cyan digital signs overhead. Zero people, pure atmosphere. Clean geometric lines, breathing room. Deep purple ambient lighting with neon highlights. 1920x1080 widescreen, minimal aesthetic, premium quality."

    # Variation 4: Rooftop view
    "Cyberpunk city rooftop view at night, minimal anime aesthetic. Foreground shows AC units and antenna in silhouette, mid-ground has layered purple buildings with pink and cyan neon windows. Distance fades into deep purple atmospheric haze. Rain creates soft bokeh. Clean composition with depth layers. Moody cinematic lighting, neon glow. 1920x1080 widescreen wallpaper, minimal design, masterpiece quality."

    # Variation 5: Convenience store exterior
    "Glowing 24-hour convenience store in cyberpunk night, minimal anime style. Wide shot shows bright interior spilling purple and cyan light onto wet pavement. Automatic doors reflect pink neon. Empty street, vending machines outside glow. Rain creates atmosphere. Clean minimal composition. Deep purple night, neon highlights. 1920x1080 widescreen, atmospheric quality."

    # Variation 6: Highway underpass
    "Cyberpunk highway underpass at night, minimal anime aesthetic. Low angle shows wet concrete with purple and pink neon light streaks from passing traffic above. Cyan emergency lights line pillars. Empty pedestrian path, atmospheric fog. Rain-slicked surfaces, bokeh effects. Clean geometric composition with strong perspective. Moody purple lighting, neon accents. 1920x1080 widescreen wallpaper, cinematic quality."
)

DESCRIPTIONS=(
    "Classic Street"
    "Alley Stairs"
    "Train Platform"
    "Rooftop View"
    "Convenience Store"
    "Highway Underpass"
)

# Generate all 6
for i in {0..5}; do
    NUM=$((i + 1))
    PROMPT="${PROMPTS[$i]}"
    DESC="${DESCRIPTIONS[$i]}"

    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
    echo "[$NUM/6] $DESC"
    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"

    WORKFLOW=$(cat <<EOF
{
  "prompt": {
    "1": {"inputs": {"unet_name": "z_image_turbo_bf16.safetensors", "weight_dtype": "default"}, "class_type": "UNETLoader"},
    "2": {"inputs": {"clip_name": "qwen_3_4b.safetensors", "type": "qwen_image"}, "class_type": "CLIPLoader"},
    "3": {"inputs": {"vae_name": "ae.safetensors"}, "class_type": "VAELoader"},
    "4": {"inputs": {"text": "$PROMPT", "clip": ["2", 0]}, "class_type": "CLIPTextEncode"},
    "5": {"inputs": {"text": "low quality, blurry, people, crowds, cars, text, watermark", "clip": ["2", 0]}, "class_type": "CLIPTextEncode"},
    "6": {"inputs": {"width": 1920, "height": 1080, "batch_size": 1}, "class_type": "EmptyLatentImage"},
    "7": {"inputs": {"seed": $(python3 -c "import random; print(random.randint(1, 2**32-1))"), "steps": 8, "cfg": 1.0, "sampler_name": "euler", "scheduler": "sgm_uniform", "denoise": 1, "model": ["1", 0], "positive": ["4", 0], "negative": ["5", 0], "latent_image": ["6", 0]}, "class_type": "KSampler"},
    "8": {"inputs": {"samples": ["7", 0], "vae": ["3", 0]}, "class_type": "VAEDecode"},
    "9": {"inputs": {"filename_prefix": "neoncyber_batch_${DATE}_v${NUM}", "images": ["8", 0]}, "class_type": "SaveImage"}
  }
}
EOF
)

    RESPONSE=$(curl -s -X POST "$COMFYUI/prompt" -H "Content-Type: application/json" -d "$WORKFLOW")
    PROMPT_ID=$(echo "$RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin).get('prompt_id', ''))" 2>/dev/null || echo "")

    if [ -n "$PROMPT_ID" ]; then
        echo "✅ Queued: $PROMPT_ID"
    else
        echo "❌ Failed to queue"
    fi

    echo ""
done

echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✨ All 6 variations queued!"
echo "⏳ Total generation time: ~6 minutes (60s each)"
echo ""
echo "Files will be named:"
echo "  neoncyber_batch_${DATE}_v1_*.png - Classic Street"
echo "  neoncyber_batch_${DATE}_v2_*.png - Alley Stairs"
echo "  neoncyber_batch_${DATE}_v3_*.png - Train Platform"
echo "  neoncyber_batch_${DATE}_v4_*.png - Rooftop View"
echo "  neoncyber_batch_${DATE}_v5_*.png - Convenience Store"
echo "  neoncyber_batch_${DATE}_v6_*.png - Highway Underpass"
echo ""
echo "🎨 Pick your favorites and let's iterate from there!"
