#!/bin/bash
# ComfyUI Best Of - Generate top prompts from history
# Optimized for Cloudflare Lucid Origin model

set -e

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
OUTPUT_DIR="$SCRIPT_DIR/../renders/comfyui-classics-$(date +%Y%m%d)"

mkdir -p "$OUTPUT_DIR"

echo "Generating ComfyUI classics with Cloudflare..."
echo "Output: $OUTPUT_DIR"

# Function to generate with Lucid Origin
generate() {
    local prompt="$1"
    local prefix="$2"

    bash "$SCRIPT_DIR/../../shared/scripts/cf-generate-wp.sh" "$prompt" "$OUTPUT_DIR" "$prefix" 8
}

# 1. Pixel Sort Glitch (from wp_glitch_003225_v1)
generate "Cyberpunk street with aggressive vertical pixel sorting glitch, anime aesthetic. Neon signs streak downward in magenta and cyan vertical columns. Reality sorted by brightness creating abstract data streams. Buildings dissolve into vertical data streams. Wet pavement reflects sorted pixel columns. Empty atmosphere with maximum digital corruption. CGA color palette: magenta, cyan, black. Glitch art meets cyberpunk. 1920x1080 widescreen masterpiece." "comfy_glitch_pixelsort"

# 2. RGB Shift Chromatic (from wp_glitch_003225_v2)
generate "Narrow alley with extreme horizontal RGB color separation, minimal anime style. Every neon sign splits into red, green, blue offset copies. Reality sliding apart chromatic aberration. Stairs descend through color-separated fog. Wet surfaces triple the RGB ghost images. Purple base with cyan and magenta displacement. Empty glitch atmosphere. Digital corruption aesthetic. 1920x1080 widescreen masterpiece." "comfy_glitch_rgbshift"

# 3. Databending Store (from wp_glitch_003225_v3)
generate "24-hour convenience store with databending corruption, cyberpunk glitch aesthetic. Store signage becomes abstract barcode patterns. Vending machines render as vertical scan line artifacts. Reality compressed and corrupted like JPEG artifacts. Magenta and cyan block compression errors. Wet floor reflects glitched data patterns. Empty digital decay. 1920x1080 widescreen corrupted file masterpiece." "comfy_glitch_databend"

# 4. Asemic Text (from wp_glitch_003225_v4)
generate "Cyberpunk city where all neon signs become asemic corrupted pixel text, anime aesthetic. Kanji and characters melt into abstract glitch symbols. Vertical text flows downward like digital waterfalls. CGA palette magenta and cyan letterforms corrupt and merge. Wet street reflects unreadable data. Empty mysterious atmosphere. Pixel sorting meets typography corruption. 1920x1080 widescreen asemic glitch masterpiece." "comfy_glitch_asemic"

# 5. B/W + Magenta Sign (from wp_bw_003759_v1)
generate "Black and white cyberpunk alley with pixel sorting glitch, anime aesthetic. Entire scene monochrome except one vertical neon sign in vivid magenta. Gray wet pavement, white highlights, black shadows. The single magenta sign streaks vertically through pixel sort effect. Everything else pure grayscale. Empty atmospheric noir with one color accent. 1920x1080 widescreen selective color masterpiece." "comfy_bw_magenta"

# 6. B/W + Cyan Vending (from wp_bw_003759_v2)
generate "Monochrome cyberpunk street with databending corruption, minimal style. Black, white, and gray tones dominate. Single vending machine glows in pure electric cyan - only color in entire scene. Grayscale buildings, white wet pavement reflections, black sky. Cyan machine creates stark contrast. Digital glitch artifacts in monochrome. 1920x1080 widescreen color isolation masterpiece." "comfy_bw_cyan"

# 7. Bedroom Window POV (from wp_bedroom_123755_v1)
generate "First person POV from dark bedroom desk looking out window at neon cyberpunk city, minimal anime aesthetic. Foreground: silhouette of monitor and keyboard on desk. Window shows magenta and cyan neon cityscape with rain. Cozy dark room interior contrasts with bright neon outside. Empty contemplative atmosphere. Bokeh city lights through wet window. 1920x1080 widescreen bedroom window masterpiece." "comfy_bedroom_pov"

# 8. Bedroom Rain Bokeh (from wp_bedroom_123755_v3)
generate "Bedroom window with heavy rain and neon bokeh beyond, minimal anime style. Close-up on rain-covered window glass. Out of focus magenta and cyan city lights create dreamy bokeh. Water droplets on glass catch neon reflections. Dark room interior barely visible. Empty peaceful rainy night mood. 1920x1080 widescreen rain bokeh masterpiece." "comfy_bedroom_rain"

# 9. Split Composition (from wp_bedroom_123755_v10)
generate "Bedroom composition split perfectly: left dark interior, right bright neon city window, minimal anime. Geometric split down center. Left: empty dark room shadows. Right: vibrant magenta and cyan cityscape. Perfect symmetry. Contrast between private/public, dark/bright, empty/busy. 1920x1080 widescreen split composition masterpiece." "comfy_bedroom_split"

# 10. Dense Arcade Interior (from wp_interior_123804_v3)
generate "Narrow arcade corridor packed with glowing game cabinets, cyberpunk glitch aesthetic. Tight hallway lined with vertical arcade machines. Purple, cyan, and magenta screens create overlapping light. Neon reflections on polished floor. Empty arcade, machines running idle. Pixel sorting on game screens. Nostalgic meets futuristic. 1920x1080 widescreen arcade corridor masterpiece." "comfy_interior_arcade"

# 11. Ramen Shop Signs (from wp_interior_123804_v4)
generate "Small ramen shop interior with dense Japanese neon menu signs, minimal anime style. Counter perspective looking at wall of vertical neon kanji signs. Red, cyan, and yellow neon layers overlap. Steam rising from kitchen implied by atmospheric haze. Empty shop, closed or waiting. Intimate cozy chaos. 1920x1080 widescreen ramen shop masterpiece." "comfy_interior_ramen"

# 12. Vending Machine Alley (from wp_interior_123804_v5)
generate "Narrow alley completely lined with glowing vending machines, cyberpunk aesthetic. Tight passage between two walls of illuminated vending machines. Cyan, magenta, and orange machine screens create tunnel of light. Wet floor reflects double the neon. Empty atmospheric corridor. Glitch artifacts on machine displays. 1920x1080 widescreen vending alley masterpiece." "comfy_interior_vending"

# 13. Mecha Penrose Hangar (from wp_mecha_003559_v1)
generate "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." "comfy_mecha_penrose"

# 14. Mecha Tesseract Projection (from wp_mecha_003559_v2)
generate "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 masterpiece." "comfy_mecha_tesseract"

# 15. Mecha Fractal Cathedral (from wp_mecha_003559_v5)
generate "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." "comfy_mecha_fractal"

# 16. Mecha Klein Bottle Tanks (from wp_mecha_003559_v6)
generate "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 masterpiece." "comfy_mecha_klein"

# 17. Marathon Terminal (from wp_marathon_004205_v1)
generate "Ancient alien terminal room in Marathon style, far-future minimalist aesthetic. Geometric brutalist architecture with vertical green phosphor text terminals embedded in walls. Cyan circuit patterns on dark metallic surfaces. Empty corridor with harsh angular shadows. Green and cyan low-fi computer interface glow. Retro-future 90s sci-fi aesthetic. Clean geometric composition, no organic elements. 1920x1080 widescreen Marathon terminal masterpiece." "comfy_marathon_terminal"

# 18. Pfhor Architecture (from wp_marathon_004205_v2)
generate "Alien Pfhor architecture corridor in Marathon aesthetic, far-future geometric style. Purple and red angular brutalist design. Alien glyphs and symbols on metallic panels. Harsh lighting creating dramatic geometric shadows. Empty lonely space station corridor. Clean minimal alien architecture. Low polygon retro-future aesthetic. Glitch artifacts on alien text. 1920x1080 widescreen Pfhor design masterpiece." "comfy_marathon_pfhor"

# 19. Jjaro Artifact Chamber (from wp_marathon_004205_v4)
generate "Ancient Jjaro civilization artifact chamber in Marathon aesthetic. Impossibly geometric alien architecture - perfect angular forms. Cyan and purple energy glows from alien technology. Massive geometric pillars and platforms. Empty archaeological discovery atmosphere. Far-future meets ancient alien. Clean minimal composition. Mathematical precision in architecture. 1920x1080 widescreen Jjaro mystery masterpiece." "comfy_marathon_jjaro"

# 20. Melting Clock Surreal (from showcase_20260308_010654_C_01)
generate "Black and white alley, only single neon sign in magenta. Selective color. Melting clock hanging on empty wall. Clock face dripping time like Salvador Dali. Room otherwise minimal. Dream logic, impossible physics. Matte black clock with cyan numerals. Against white wall. Surreal time, impossible physics. 1920x1080 widescreen masterpiece." "comfy_surreal_clock"

echo "ComfyUI classics batch complete!"
echo "Generated 20 wallpapers from best ComfyUI prompts."

# Count
GENERATED=$(find "$OUTPUT_DIR" -type f -name "*.jpg" 2>/dev/null | wc -l)
echo "Total: $GENERATED wallpapers"