import type { WorkSession } from "../workSession.schema"
import type { FrontendPayloadRequestData, PluginFastifyInstance } from "types"

export const registerPayload = (fastify: PluginFastifyInstance) => {
  fastify.registerPayloadHandler<WorkSession>("workSession", {
    type: "workSession",
    displayName: (workSession: WorkSession) => workSession._id || "",
    completion: (workSession: WorkSession) => workSession._id || "",
    fields: () => ({
      owner: "NONE",
    }),
  })
}

export const createWorkSessionPayload = async (
  fastify: PluginFastifyInstance,
  items: WorkSession[],
  requestData: FrontendPayloadRequestData,
) => {
  return await fastify.createPayload("workSession", items, requestData)
}
