import type { Tag } from "../tag.schema"
import type { FrontendPayloadRequestData, PluginFastifyInstance } from "types"

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

export const createTagPayload = async (
  fastify: PluginFastifyInstance,
  items: Tag[],
  requestData: FrontendPayloadRequestData,
) => {
  return await fastify.createPayload("tag", items, requestData)
}
