/**
 * broadcastToTenant — queue-consumer → DO fan-out helper (real-time-infrastructure).
 *
 * Internal to the `zync-realtime` queue consumer: gets the per-tenant DO stub and
 * POSTs the fully-formed event so the DO fans it out to all (or the targetUserId's)
 * open WebSocket sessions. NOT a public emit API — route handlers publish via
 * `publishRealtimeEvent(env.REALTIME_QUEUE, …)` from `@zync/realtime`.
 *
 * Addressed via `env.DO_REALTIME` by name `tenant:{tenantId}`.
 * Failures are non-fatal — the consumer continues even if the DO is unreachable.
 */
import type { Env } from '@zync/types'
import type { RealtimeEvent } from '@zync/realtime'
import { dispatchPlatformRealtimeEvent } from '../integrations/platform/realtime'

export async function broadcastToTenant(
  env: Env,
  tenantId: string,
  event: RealtimeEvent,
): Promise<void> {
  await dispatchPlatformRealtimeEvent(env, {
    ...event,
    tenantId,
  })
}
