import Tag from '../models/tag.js'

export async function validateTagSlugs(slugs) {
  if (!slugs?.length) return
  const foundTags = await Tag.find({ slug: { $in: slugs } })
  const foundSlugs = new Set(foundTags.map(t => t.slug))
  const invalid = slugs.filter(s => !foundSlugs.has(s))
  if (invalid.length > 0) {
    throw createError({
      statusCode: 400,
      statusMessage: `Unknown tag slugs: ${invalid.join(', ')}`
    })
  }
}
