import { z } from "zod";
import {
  createTRPCRouter,
  protectedApiProcedure,
  publicProcedure,
} from "~/server/api/trpc";
import {
  addEventToQueue,
  processEvents,
} from "~/server/controllers/event_queue.controller";
import { zEventDataTypes } from "~/server/utils/zod_types";

export const eventQueueRouter = createTRPCRouter({
  addEvent: publicProcedure
    .input(
      z.object({
        lock_expires: z.date(),
        data: zEventDataTypes,
      }),
    )
    .mutation(async ({ input }) => {
      return await addEventToQueue(input);
    }),
  processEvents: protectedApiProcedure.query(async () => {
    return await processEvents();
  }),
});
