import { SalesOrder, SalesQuote } from "@open-mercato/core/modules/sales/data/entities";
import { createLogger } from "@open-mercato/shared/lib/logger";
const logger = createLogger("sales");
const metadata = {
  event: "customers.company.deleted",
  persistent: true,
  id: "sales:reconcile-on-company-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 Promise.all([
      em.nativeUpdate(
        SalesOrder,
        { customerEntityId: entityId, tenantId },
        { customerEntityId: null }
      ),
      em.nativeUpdate(
        SalesQuote,
        { customerEntityId: entityId, tenantId },
        { customerEntityId: null }
      )
    ]);
  } catch (err) {
    logger.error("sales.reconcile-on-company-delete Failed to null customerEntityId on sales documents", { err });
  }
}
export {
  handle as default,
  metadata
};
//# sourceMappingURL=reconcileOnCompanyDelete.js.map
