// Copy to `src/subscribers/customer.ts` in your Medusa project.
//
// Event names verified against the installed @medusajs/utils 2.13.6
// CustomerWorkflowEvents constant (dist/core-flows/events.js). Payload is
// `{ id }` (the customer id) for all three.
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework";
import { sendTenderPosWebhook } from "../lib/tender-pos-webhook";

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

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

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