#!/bin/bash
# NEONCYBER - Pure Creative Chaos
# No rules, just vibes
# Usage: ./generate-chaos.sh

set -e

COMFYUI="http://192.168.1.57:8188"
TIMESTAMP=$(date +%H%M%S)

echo "🌀 NEONCYBER - CREATIVE CHAOS"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "No rules. Just vibes. Pure creativity."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

PROMPTS=(
    # 1: Liquid architecture melting upward
    "Cyberpunk architecture melting upward defying gravity in liquid chrome, minimal anime aesthetic. Buildings flow like mercury into purple sky. Pixel sorted streams of molten neon cascade in reverse. Gold and cyan metal drips upward creating impossible towers. Wet pavement mirrors the inverted flow. Empty surreal dreamscape. Reality rendered as fluid simulation glitch. 1920x1080 widescreen, liquid gravity masterpiece."

    # 2: Holographic origami city
    "City folded like holographic origami with creased light, far-future minimal style. Buildings bend at impossible angles creating geometric paper crane structures. Translucent cyan and magenta fold lines glow. Reality creased and pleated into abstract forms. Empty space between dimensional folds. Mathematical beauty meets digital ethereal. Wireframe edges on folded surfaces. 1920x1080 widescreen, origami dimension quality."

    # 3: Neon archaeology excavation
    "Archaeological dig site excavating layers of compressed neon light, glitch aesthetic. Vertical strata of magenta, cyan, gold, purple light compressed like geological time. Ancient future buried in color sediment. Excavation tools made of wireframe geometry. Empty temporal mining operation. Digital fossil layers. Each stratum different era of glitch corruption. 1920x1080 widescreen, neon archaeology masterpiece."

    # 4: Quantum superposition street
    "Single cyberpunk street existing in quantum superposition showing all possible states simultaneously, anime style. Same alley rendered in orange/teal AND red/cyan AND gold/black all overlapping transparently. Multiple color timeline collapsed into one image. Ghostly interference patterns where realities overlap. Empty probability space. Schrodinger's cityscape. 1920x1080 widescreen, quantum aesthetic quality."

    # 5: Crystallized time corridor
    "Corridor where time itself crystallizes into geometric shards, minimal far-future style. Frozen moments rendered as floating cyan and purple crystal formations. Motion blur crystallized mid-movement creating impossible frozen trajectories. Empty hallway filled with time debris. Mathematical time geometry. Each crystal contains different temporal fragment. Digital time corruption. 1920x1080 widescreen, crystallized time masterpiece."

    # 6: Negative space inversion
    "Cyberpunk scene where negative space becomes solid and architecture becomes void, glitch aesthetic. What should be empty air glows in magenta and cyan. Buildings and streets rendered as pure black negative cutouts. Reality inverted like photographic negative with color corruption. Empty becomes full, solid becomes void. Impossible figure-ground reversal. 1920x1080 widescreen, inverted reality quality."
)

DESCRIPTIONS=(
    "Liquid Gravity"
    "Holographic Origami"
    "Neon Archaeology"
    "Quantum Superposition"
    "Crystallized Time"
    "Negative Space Inversion"
)

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, normal, realistic, boring", "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": "wp/wp_chaos_${TIMESTAMP}_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 chaos variations queued!"
echo ""
echo "📁 Files: ComfyUI/output/wp/"
echo "  wp_chaos_${TIMESTAMP}_v1_*.png - Liquid Gravity"
echo "  wp_chaos_${TIMESTAMP}_v2_*.png - Holographic Origami"
echo "  wp_chaos_${TIMESTAMP}_v3_*.png - Neon Archaeology"
echo "  wp_chaos_${TIMESTAMP}_v4_*.png - Quantum Superposition"
echo "  wp_chaos_${TIMESTAMP}_v5_*.png - Crystallized Time"
echo "  wp_chaos_${TIMESTAMP}_v6_*.png - Negative Space Inversion"
echo ""
echo "🌀 PURE CREATIVE CHAOS INCOMING!"
