export default defineEventHandler(async (event) => {
  const userId: string = event.context.params ? event.context.params.id : '@me'

  const user = await getUser(userId, event)

  if (user.$isEmpty('minecraft') || !user.minecraft) {
    throw createError({ statusCode: 400, statusMessage: 'Minecraft has not been linked' })
  }

  try {
    await WhitelistModel.deleteOne({ uuid: user.minecraft.uuid })
    user.minecraft = undefined

    await applyUsername(user)
  } catch (e) {
    console.error('Failed to update documents', e)

    throw createError('Failed to update documents')
  }

  return ''
})
