/**
 * community blueprint · wiring seam for `@platform-modules/realtime`.
 *
 * realtime's CORE barrel is TYPE-ONLY (the isomorphic wire contract); the built Workers
 * Durable-Object/Queue delivery lives behind the `/server` subpath, which is Workers-locked and
 * host-wired — out of this blueprint's scope. So this seam wires only the envelope contract.
 *
 * Like saas-admin's ledger seam, this file NAMES the host-owned seam instead of exercising it: it
 * builds the typed `RealtimeEvent` envelope the host would publish to followers' live connections
 * when a post goes live. The composition test asserts the ENVELOPE is well-formed (the contract the
 * browser pins against); it does NOT deliver — delivery is host-owned (`/server`, out of scope here).
 */
import type { RealtimeEvent } from '@platform-modules/realtime'

export type PostPublishedPayload = { postId: string; authorId: string; title: string }
export type PostPublishedEvent = RealtimeEvent<'post.published', PostPublishedPayload>

/**
 * Construct the envelope the host publishes to followers' realtime connections. `scope` is the
 * routing key the host names (here the author's follower-feed channel). No `targetUserId` ⇒ scope-
 * wide delivery (a public post fans to the whole feed channel). `id`/`timestamp` are caller-supplied
 * so this stays pure — the host stamps a UUID + ISO time from request context (no Date.now/randomUUID
 * at the seam).
 */
export function postPublishedEvent(args: {
  id: string
  scope: string
  timestamp: string
  payload: PostPublishedPayload
}): PostPublishedEvent {
  return {
    id: args.id,
    type: 'post.published',
    scope: args.scope,
    payload: args.payload,
    timestamp: args.timestamp,
  }
}
