export default defineEventHandler(async (event) => {
  const { content, uuid } = await readBody(event);

  const config = useRuntimeConfig();

  const usersColl = db.collection('users')
  const user = await usersColl.findOne({ 'minecraft.uuid': uuid })

  const response = await getUsernameWithTeam(user);

  await $fetch(config.discordHost + '/minecraft/sendchatmessage', {
    method: 'POST',
    body: {
      username: response.usernameWithoutStyle,
      // avatarURL: 'https://cdn.discordapp.com/avatars/' + doc.discord.id + '/' + doc.discord.avatarHash + '.png',
      avatarURL: 'https://api.mineatar.io/face/' + user.minecraft.uuid + '?scale=16',
      content: content,
    }
  })

  return { code: 'success' }
});
