import { Type } from "@sinclair/typebox"
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify"

export default (fastify: FastifyInstance) => {
  const handler = async (req: FastifyRequest, reply: FastifyReply) => {
    fastify.eventbus.emit("broadcastNewVersionAvailable")
    fastify.log.info(`[eventbus] new version deployed`)

    reply.send({ success: true })
  }

  return {
    handler,
    schema: {
      summary: "Will trigger a new deployment information for the websockets",
      tags: ["system"],
      response: {
        200: Type.Object({
          success: Type.Boolean(),
        }),
      },
    },
  }
}
