import { transformOrderWebhookPayload, type OrderWebhookPayload } from '../transformers'
import * as bp from '.botpress'

type FireEventProps = bp.HandlerProps & { payload: OrderWebhookPayload }

export const fireOrderFulfilled = async ({ payload, client, logger }: FireEventProps) => {
  logger.forBot().info(`Received order fulfilled event for order ${payload.name} (${payload.id})`)

  await client.createEvent({
    type: 'orderFulfilled',
    payload: transformOrderWebhookPayload(payload),
  })
}
