import type { Project } from "../project.schema"
import type { FrontendPayloadRequestData, PluginFastifyInstance } from "types"

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

export const createProjectPayload = async (
  fastify: PluginFastifyInstance,
  items: Project[],
  requestData: FrontendPayloadRequestData,
) => {
  return await fastify.createPayload("project", items, requestData)
}
