-- Debug script to check Printful variant data
-- Run this to see what variant IDs are stored after Printful sync

-- Check product variants with Printful IDs
SELECT 
    pv.id,
    pv.product_id,
    p.name as product_name,
    pv.size,
    pv.color,
    pv.printful_variant_id,
    pv.sku
FROM product_variants pv
JOIN products p ON pv.product_id = p.id
WHERE pv.printful_variant_id IS NOT NULL
ORDER BY pv.product_id, pv.size, pv.color
LIMIT 10;

-- Check recent order items and their variant IDs
SELECT 
    oi.id,
    oi.order_id,
    oi.product_id,
    oi.variant_id,
    p.name as product_name,
    pv.size,
    pv.color,
    pv.printful_variant_id,
    o.created_at
FROM order_items oi
JOIN products p ON oi.product_id = p.id
JOIN product_variants pv ON oi.variant_id = pv.id
JOIN orders o ON oi.order_id = o.id
ORDER BY o.created_at DESC
LIMIT 5;

-- Check if any variants are missing Printful IDs
SELECT COUNT(*) as total_variants,
       SUM(CASE WHEN printful_variant_id IS NOT NULL THEN 1 ELSE 0 END) as with_printful_id,
       SUM(CASE WHEN printful_variant_id IS NULL THEN 1 ELSE 0 END) as missing_printful_id
FROM product_variants;