import { requireAuth } from '../../utils/auth.js'
import BoardPost from '../../models/boardPost.js'

export default defineEventHandler(async (event) => {
  const member = await requireAuth(event)

  const hasProfileTags = member.craftTags.length > 0

  const hasVisitedEvent = !!member.onboarding?.eventPageVisited

  const hasPosted = await BoardPost.exists({ author: member._id })
  const hasEngagedBoard =
    !!member.onboarding?.boardPageVisited && !!hasPosted

  const hasClickedWiki = !!member.onboarding?.wikiClicked

  const skipped = member.onboarding?.skipped || {}

  return {
    goals: {
      hasProfileTags,
      hasVisitedEvent,
      hasEngagedBoard,
      hasClickedWiki,
    },
    skipped: {
      profileTags: !!skipped.profileTags,
      visitEvent: !!skipped.visitEvent,
      board: !!skipped.board,
      wiki: !!skipped.wiki,
    },
    completedAt: member.onboarding?.completedAt || null,
  }
})
