#!/bin/bash
# NEONCYBER - Mecha + Impossible Geometry
# SYNTHLIEF-inspired geometric patterns meets mecha aesthetic
# Usage: ./generate-mecha-geometry.sh

set -e

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

echo "🤖 NEONCYBER - Mecha + Impossible Geometry"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "SYNTHLIEF geometry + mecha aesthetic + glitch"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

PROMPTS=(
    # 1: Penrose triangle hangar
    "Massive mecha hangar bay with impossible Penrose triangle architecture, minimal cyberpunk anime style. Industrial geometric structure defies physics - triangle loops infinitely. Magenta and cyan hazard lights illuminate the paradox. Empty hangar floor with oil puddles reflecting impossible geometry. Brutalist concrete meets mathematical impossibility. Digital glitch artifacts around the triangle edges. 1920x1080 widescreen, impossible architecture masterpiece."

    # 2: Hypercube mecha parts
    "Deconstructed mecha parts arranged in hypercube projection pattern, glitch aesthetic. Robot limbs and armor plates phase through 4D space creating impossible overlaps. Magenta and cyan neon highlights on chrome surfaces. Parts exist in multiple perspectives simultaneously. Wet workshop floor reflects the geometric paradox. Empty industrial space with mathematical beauty. 1920x1080 widescreen, 4D mecha quality."

    # 3: Tesseract unfolding garage
    "Underground mecha garage where walls unfold like tesseract geometry, minimal anime style. Concrete panels rotate through impossible dimensions. Robot maintenance bay revealed through geometric transformation. Cyan and purple neon strips mark the folding edges. Wet floor mirrors the dimensional shift. Empty surreal mechanical space. Pixel sort glitch on unfolding surfaces. 1920x1080 widescreen, dimensional garage masterpiece."

    # 4: Möbius strip conveyor
    "Mecha assembly conveyor belt twisted into Möbius strip topology, cyberpunk glitch aesthetic. Robot parts travel on impossible single-sided loop. Industrial yellow safety stripes follow the twist. Magenta warning lights, cyan welding sparks. Empty automated factory with mathematical madness. Chrome surfaces reflect the paradox. Digital artifacts where topology breaks reality. 1920x1080 widescreen, impossible factory quality."

    # 5: Fractal cathedral hangar
    "Mecha storage hangar designed as fractal cathedral architecture, minimal anime style. Infinite recursive pillars create impossible depth. Robot silhouettes stored in fractal alcoves. Purple and cyan sacred geometry lighting. Wet industrial floor reflects infinite patterns. Empty mechanical temple atmosphere. Glitch corruption on repeating patterns. 1920x1080 widescreen, fractal mecha shrine masterpiece."

    # 6: Klein bottle fuel tank
    "Massive mecha fuel tanks designed as Klein bottle impossible topology, cyberpunk aesthetic. Fuel flows through bottle with no inside or outside. Cyan coolant liquid defies physics. Industrial pipes connect to impossible surface. Magenta pressure gauges, purple atmospheric lighting. Wet concrete floor reflects the paradox. Empty industrial surrealism. Pixel sorting on liquid surface. 1920x1080 widescreen, impossible engineering quality."
)

DESCRIPTIONS=(
    "Penrose Triangle Hangar"
    "Hypercube Mecha Parts"
    "Tesseract Garage"
    "Möbius Conveyor"
    "Fractal Cathedral Hangar"
    "Klein Bottle Fuel Tank"
)

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, monsters, creatures, organic beings", "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_mecha_${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 mecha geometry variations queued!"
echo ""
echo "📁 Files: ComfyUI/output/wp/"
echo "  wp_mecha_${TIMESTAMP}_v1_*.png - Penrose Triangle Hangar"
echo "  wp_mecha_${TIMESTAMP}_v2_*.png - Hypercube Mecha Parts"
echo "  wp_mecha_${TIMESTAMP}_v3_*.png - Tesseract Garage"
echo "  wp_mecha_${TIMESTAMP}_v4_*.png - Möbius Conveyor"
echo "  wp_mecha_${TIMESTAMP}_v5_*.png - Fractal Cathedral Hangar"
echo "  wp_mecha_${TIMESTAMP}_v6_*.png - Klein Bottle Fuel Tank"
echo ""
echo "🤖 Impossible mecha geometry incoming!"
