/**
 * This file was generated by @pikku/cli@0.12.23
 */
/**
 * Auto-generated remote internal RPC queue worker and HTTP endpoint
 * Do not edit manually - regenerate with 'npx pikku'
 */
import { pikkuSessionlessFunc, wireHTTP, wireQueueWorker } from '@project/functions/.pikku/pikku-types.gen.js'
import { pikkuRemoteAuthMiddleware } from '@pikku/core/middleware'

export const remoteRPCHandler = pikkuSessionlessFunc<
  { rpcName: string, data?: unknown },
  unknown
>({
  tags: ['pikku'],
  func: async (_services, { rpcName, data }, { rpc }) => {
    return await (rpc.invoke as any)(rpcName, data)
  },
  remote: true,
})

wireQueueWorker({
  name: 'pikku-remote-internal-rpc',
  func: remoteRPCHandler,
})

wireHTTP({
  route: '/remote/rpc/:rpcName',
  method: 'post',
  auth: false,
  middleware: [pikkuRemoteAuthMiddleware],
  func: remoteRPCHandler,
})
