#!/bin/bash
# Select best product image and generate prompts using Claude Code
# Usage: ./select_and_prompt.sh <directory_with_images> [product_name]

set -e

IMAGE_DIR="${1:-.}"
PRODUCT_NAME="${2:-Product}"

# Find all images in directory
IMAGES=$(find "$IMAGE_DIR" -maxdepth 1 -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.webp" \) | sort)

if [ -z "$IMAGES" ]; then
    echo "No images found in $IMAGE_DIR"
    exit 1
fi

echo "Found images:"
echo "$IMAGES" | while read img; do echo "  - $(basename "$img")"; done
echo ""

# Build the prompt with image paths
IMAGE_LIST=$(echo "$IMAGES" | tr '\n' ' ')

# Run Claude Code non-interactively
claude -p "You are analyzing product images for video generation.

Product: $PRODUCT_NAME

Look at these images and:
1. SELECT the best image for a promotional video (criteria: clear product visibility, minimal text/overlays, good lighting, simple background, product centered)
2. EXPLAIN why you chose it (1-2 sentences)
3. Generate a NANOBANANA prompt to clean up the image (remove text, watermarks, resize to 16:9)
4. Generate a VEO3 prompt for an 8-second product video

Images to analyze: $IMAGE_LIST

Output as JSON:
{
  \"selected_image\": \"filename\",
  \"reason\": \"...\",
  \"nanobanana_prompt\": \"...\",
  \"veo3_prompt\": \"...\"
}"
