// Copy to `src/subscribers/product.ts` in your Medusa project.
//
// Event names verified against the installed @medusajs/utils 2.13.6
// ProductWorkflowEvents constant (dist/core-flows/events.js) — product
// events carry only `{ id }` (the product id), never the full product body,
// so there is nothing to resolve here beyond forwarding the id.
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework";
import { sendTenderPosWebhook } from "../lib/tender-pos-webhook";

export default async function tenderPosProductHandler({
  event: { name, data },
  container,
}: SubscriberArgs<{ id: string }>) {
  const logger = container.resolve("logger");

  await sendTenderPosWebhook({
    topic: name,
    data: { resourceType: "product", id: data.id },
    logger,
  });
}

export const config: SubscriberConfig = {
  event: ["product.created", "product.updated", "product.deleted"],
  context: { subscriberId: "tender-pos-product" },
};
