#!/bin/bash
echo "=== Products with cutout ==="
docker exec supabase-db psql -U postgres -d sneakerpicks -t -c "SELECT COUNT(*) FROM products WHERE cutout_image_url IS NOT NULL AND is_sneaker = true"

echo "=== Products without cutout ==="
docker exec supabase-db psql -U postgres -d sneakerpicks -t -c "SELECT COUNT(*) FROM products WHERE cutout_image_url IS NULL AND is_sneaker = true"

echo "=== Sample Campus products ==="
docker exec supabase-db psql -U postgres -d sneakerpicks -c "SELECT id, LEFT(name,40) as name, cutout_image_url, LEFT(image_url,60) as img FROM products WHERE name ILIKE '%campus%' AND brand ILIKE '%adidas%' AND is_sneaker = true LIMIT 5"

echo "=== Check if cutout files exist for those ==="
for id in $(docker exec supabase-db psql -U postgres -d sneakerpicks -t -c "SELECT id FROM products WHERE name ILIKE '%campus%' AND brand ILIKE '%adidas%' AND is_sneaker = true LIMIT 5"); do
    id=$(echo $id | tr -d ' ')
    if [ -f "/var/www/sneakerpicks/public/cutouts/${id}.png" ]; then
        echo "$id: FILE EXISTS ($(stat -c%s /var/www/sneakerpicks/public/cutouts/${id}.png) bytes)"
    else
        echo "$id: MISSING"
    fi
done

echo "=== Broken cutout URLs (have URL but no file) - sample ==="
for id in $(docker exec supabase-db psql -U postgres -d sneakerpicks -t -c "SELECT id FROM products WHERE cutout_image_url IS NOT NULL AND is_sneaker = true ORDER BY RANDOM() LIMIT 20"); do
    id=$(echo $id | tr -d ' ')
    if [ ! -f "/var/www/sneakerpicks/public/cutouts/${id}.png" ]; then
        echo "$id: DB says cutout exists but FILE MISSING"
    fi
done
