#!/bin/bash
# NEONCYBER - FLUX.1 [dev] High Quality Upgrade
# Regenerate favorite prompts with FLUX for top-notch wallpaper quality
# Usage: ./generate-flux.sh

set -e

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

echo "⚡ NEONCYBER - FLUX.1 [dev] High Quality"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Premium wallpaper quality - 20-30 steps"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

# Add your favorite prompts here after reviewing the showcase
# Example format:
PROMPTS=(
    # Copy your winning prompts from the showcase here
    "Cyberpunk alley with vertical pixel sorting glitch, minimal anime aesthetic. Neon signs streak downward through corrupted data. Magenta and cyan buildings sorted into digital columns. Wet pavement reflects glitched reality. Empty atmospheric mood with bokeh lights. Digital corruption as artistic medium. 1920x1080 widescreen, pixel sort masterpiece."

    # Add more prompts as needed...
)

DESCRIPTIONS=(
    "Vertical Pixel Sort"
    # Add corresponding descriptions...
)

for i in "${!PROMPTS[@]}"; do
    NUM=$((i + 1))
    PROMPT="${PROMPTS[$i]}"
    DESC="${DESCRIPTIONS[$i]}"

    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
    echo "[$NUM/${#PROMPTS[@]}] $DESC"
    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"

    WORKFLOW=$(cat <<EOF
{
  "prompt": {
    "1": {"inputs": {"ckpt_name": "flux1-dev.safetensors"}, "class_type": "CheckpointLoaderSimple"},
    "2": {"inputs": {"text": "$PROMPT", "clip": ["1", 1]}, "class_type": "CLIPTextEncode"},
    "3": {"inputs": {"text": "low quality, blurry, people, watermark, text, signature", "clip": ["1", 1]}, "class_type": "CLIPTextEncode"},
    "4": {"inputs": {"width": 1920, "height": 1080, "batch_size": 1}, "class_type": "EmptyLatentImage"},
    "5": {"inputs": {"seed": $(python3 -c "import random; print(random.randint(1, 2**32-1))"), "steps": 25, "cfg": 3.5, "sampler_name": "euler", "scheduler": "simple", "denoise": 1, "model": ["1", 0], "positive": ["2", 0], "negative": ["3", 0], "latent_image": ["4", 0]}, "class_type": "KSampler"},
    "6": {"inputs": {"samples": ["5", 0], "vae": ["1", 2]}, "class_type": "VAEDecode"},
    "7": {"inputs": {"filename_prefix": "wp/wp_flux_${TIMESTAMP}_v${NUM}", "images": ["6", 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 FLUX variants queued!"
echo ""
echo "📁 Files: ComfyUI/output/wp/"
echo "  wp_flux_${TIMESTAMP}_v*_*.png"
echo ""
echo "⚡ Premium quality wallpapers incoming!"
