import type { InteractionLink } from "../interactionLink.schema"
import type { PluginFastifyInstance, FrontendPayloadRequestData } from "types"

export const registerPayload = (fastify: PluginFastifyInstance) => {
  fastify.registerPayloadHandler<InteractionLink>("interactionLink", {
    type: "interactionLink",
    displayName: (interactionLink: InteractionLink) =>
      interactionLink.description ||
      `CompositionType: ${interactionLink.slotType}` ||
      "No Description",
    completion: (interactionLink: InteractionLink) =>
      interactionLink.description ||
      interactionLink.slotType ||
      "No Description",
    fields: (item: InteractionLink) => ({
      owner: item.author,
    }),
  })
}

export const createInteractionLinkPayload = async (
  fastify: PluginFastifyInstance,
  items: InteractionLink[],
  requestData: FrontendPayloadRequestData,
) => await fastify.createPayload("interactionLink", items, requestData)
