#!/bin/bash
# Test 512x512 @ 8 steps - Spider macro shot
COMFY="http://localhost:8188"

# Check server health first
HEALTH=$(curl -s -o /dev/null -w "%{http_code}" "$COMFY/api/prompt" -X GET 2>/dev/null)
echo "Server status: $HEALTH"

WORKFLOW='{
  "1": {
    "class_type": "CLIPLoaderGGUF",
    "inputs": {
      "clip_name": "Qwen_3_4b-Q8_0.gguf",
      "type": "lumina2"
    }
  },
  "2": {
    "class_type": "CLIPTextEncode",
    "inputs": {
      "text": "A hyper-realistic close-up of a spider eating a fly, cinematic lighting, extreme detail on the spider body and eyes, realistic textures of the fly and spider web, slow-motion perspective, ultra-detailed macro shot, photorealistic, depth of field, natural colors, subtle shadows and reflections, highly detailed silk threads, cinematic 8K quality, realistic motion and physics, intense focus on textures and tiny hairs, documentary-style realism, high frame rate for smooth movement",
      "clip": ["1", 0]
    }
  },
  "3": {
    "class_type": "CLIPTextEncode",
    "inputs": {
      "text": "blurry, low quality, cartoon, anime, painting, illustration, drawing, sketch, watermark, text, logo, oversaturated, plastic, smooth skin, unrealistic, deformed, mutated, extra limbs, bad anatomy, cropped, out of frame, worst quality, low resolution, ugly, duplicate, noise, jpeg artifacts, compression artifacts",
      "clip": ["1", 0]
    }
  },
  "4": {
    "class_type": "UnetLoaderGGUF",
    "inputs": {
      "unet_name": "z_image_turbo-Q5_K_S.gguf"
    }
  },
  "5": {
    "class_type": "EmptyLatentImage",
    "inputs": {
      "width": 512,
      "height": 512,
      "batch_size": 1
    }
  },
  "6": {
    "class_type": "KSampler",
    "inputs": {
      "seed": 77777,
      "steps": 8,
      "cfg": 2.0,
      "sampler_name": "euler",
      "scheduler": "normal",
      "denoise": 1.0,
      "model": ["4", 0],
      "positive": ["2", 0],
      "negative": ["3", 0],
      "latent_image": ["5", 0]
    }
  },
  "7": {
    "class_type": "VAELoader",
    "inputs": {
      "vae_name": "ae.safetensors"
    }
  },
  "8": {
    "class_type": "VAEDecode",
    "inputs": {
      "samples": ["6", 0],
      "vae": ["7", 0]
    }
  },
  "9": {
    "class_type": "SaveImage",
    "inputs": {
      "filename_prefix": "bc250_spider_512",
      "images": ["8", 0]
    }
  }
}'

echo "Submitting 512x512 spider macro test (8 steps)..."
RESP=$(curl -s -X POST "$COMFY/api/prompt" \
  -H "Content-Type: application/json" \
  -d "{\"prompt\": $WORKFLOW}")

echo "Response: $RESP"
PROMPT_ID=$(echo "$RESP" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('prompt_id','NONE'))" 2>/dev/null)
echo "Prompt ID: $PROMPT_ID"
