import { MESSAGE_ENTITY_ID } from "../lib/constants.js";
const metadata = {
  event: "messages.message.sent",
  persistent: false,
  id: "messages:query-index-reindex-sent"
};
async function handle(payload, ctx) {
  const messageId = typeof payload?.messageId === "string" ? payload.messageId : null;
  const tenantId = typeof payload?.tenantId === "string" ? payload.tenantId : null;
  if (!messageId || !tenantId) return;
  let bus = null;
  try {
    bus = ctx.resolve("eventBus");
  } catch {
    bus = null;
  }
  if (!bus) return;
  await bus.emitEvent(
    "query_index.upsert_one",
    {
      entityType: MESSAGE_ENTITY_ID,
      recordId: messageId,
      organizationId: payload.organizationId ?? null,
      tenantId,
      crudAction: "created",
      coverageBaseDelta: 1
    },
    {
      tenantId,
      organizationId: payload.organizationId ?? null
    }
  ).catch(() => void 0);
}
export {
  handle as default,
  metadata
};
//# sourceMappingURL=search-reindex-sent.js.map
