import type { Composition } from "../composition.schema"
import type { FrontendPayloadRequestData, PluginFastifyInstance } from "types"

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

export const createCompositionPayload = async (
  fastify: PluginFastifyInstance,
  items: Composition[],
  requestData: FrontendPayloadRequestData,
) => await fastify.createPayload("composition", items, requestData)
