const COMMUNICATION_CHANNELS_SYSTEM_USER_ID = "00000000-0000-0000-0000-000000000000";
function systemUserEmail(tenantId) {
  return `system+communication_channels@${tenantId}.local`;
}
async function resolveCommunicationChannelsSystemUserId(em, tenantId, fallbackId) {
  try {
    const expectedEmail = systemUserEmail(tenantId);
    const qb = em.createQueryBuilder("auth.users", "u");
    const row = await qb.select(["u.id"]).where({ email: expectedEmail, tenant_id: tenantId }).limit(1).execute("get").catch(() => null);
    const id = row?.id;
    if (typeof id === "string" && id.length > 0) return id;
  } catch {
  }
  if (typeof fallbackId === "string" && fallbackId.length > 0) return fallbackId;
  return COMMUNICATION_CHANNELS_SYSTEM_USER_ID;
}
export {
  COMMUNICATION_CHANNELS_SYSTEM_USER_ID,
  resolveCommunicationChannelsSystemUserId,
  systemUserEmail
};
//# sourceMappingURL=system-user.js.map
