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

  if (direction !== 'forward' && direction !== 'backwards') {
    throw createError({
      statusCode: 400,
      statusMessage: 'Invalid motor direction',
    })
  }

  const baseUrl = getPiBaseUrl(event)
  const config = useRuntimeConfig()

  return await $fetch(`${baseUrl}/motor/step/${direction}`, {
    method: 'POST',
    query: {
      token: config.quibotToken,
    },
  })
})
