import { CustomerUser } from "@open-mercato/core/modules/customer_accounts/data/entities";
import { createLogger } from "@open-mercato/shared/lib/logger";
const logger = createLogger("customer_accounts").child({ component: "unlink-on-person-delete" });
const metadata = {
  event: "customers.person.deleted",
  persistent: true,
  id: "customer_accounts:unlink-on-person-delete"
};
async function handle(payload, ctx) {
  const data = payload;
  const entityId = data?.entityId ?? data?.id;
  const tenantId = data?.tenantId;
  if (!entityId || !tenantId) return;
  const em = ctx.resolve("em");
  try {
    await em.nativeUpdate(
      CustomerUser,
      { personEntityId: entityId, tenantId },
      { personEntityId: null, updatedAt: /* @__PURE__ */ new Date() }
    );
  } catch (err) {
    logger.error("Failed to clear personEntityId on customer users", { err });
  }
}
export {
  handle as default,
  metadata
};
//# sourceMappingURL=unlinkOnPersonDelete.js.map
