export default defineEventHandler(async (event) => {
  const id = Number(getRouterParam(event, 'id'))

  if (!id || isNaN(id)) {
    throw createError({ statusCode: 400, statusMessage: 'ID invalide' })
  }

  const data = await readYaml<{ messages: any[] }>('messages.yml')

  const index = data.messages.findIndex(m => m.id === id)
  if (index === -1) {
    throw createError({ statusCode: 404, statusMessage: 'Message non trouvé' })
  }

  data.messages.splice(index, 1)
  await writeYaml('messages.yml', data)

  return { ok: true }
})
