-- Get 10 diverse products from different brands with images
WITH ranked AS (
  SELECT p.id, p.name, p.brand, p.image_url,
    ROW_NUMBER() OVER (PARTITION BY p.brand ORDER BY random()) as rn
  FROM products p
  WHERE p.image_url IS NOT NULL AND p.image_url != ''
    AND p.brand IS NOT NULL
)
SELECT id, name, brand, image_url
FROM ranked
WHERE rn = 1
ORDER BY random()
LIMIT 10;
