export async function validateGalleryImages(prisma, urls) {
  if (!urls || urls.length === 0) return null

  const existing = await prisma.galleryImage.findMany({
    where: { url: { in: urls } },
    select: { url: true, isResized: true },
  })

  const galleryMap = new Map(existing.map((g) => [g.url, g]))
  const notFound = urls.filter((u) => !galleryMap.has(u))
  if (notFound.length > 0) {
    throw Object.assign(new Error(`Gallery images not found: ${notFound.join(', ')}`), { statusCode: 400 })
  }

  const notResized = urls.filter((u) => galleryMap.get(u) && !galleryMap.get(u).isResized)
  if (notResized.length > 0) {
    throw Object.assign(new Error('Some gallery images have not been processed yet. Please try again later.'), {
      statusCode: 400,
    })
  }

  return existing
}
