import type { EventType } from "./eventTypes"; import { broadcast } from "@/lib/realtime/bus"; interface GameEventInput { type: EventType; message: string; actor?: number; structure?: number; targetCollection?: | "users" | "missions" | "maps" | "campaigns" | "factions" | "technologies" | "assets" | "resources" | "structures" | "vehicles" | "game-structures" | "game-vehicles" | "game-npcs" | "shipments" | "bank-accounts" | "bank-transactions" | "ledger-entries" | "locker-storages" | "loadouts" | "market-listings" | "market-negotiations" | "evaluations" | "tickets" | "game-servers" | "assignment-transfers"; targetId?: number; data?: Record; } export async function emitGameEvent( payload: Awaited>, event: GameEventInput, ) { try { await payload.create({ collection: "game-event-logs", data: { system: true, timestamp: new Date().toISOString(), type: event.type, actor: event.actor, message: event.message, data: event.data, targetCollection: event.targetCollection, targetId: event.targetId, structure: event.structure, }, depth: 0, // Bins and tests run without an authenticated user; create access on // game-event-logs requires one, so system events would be silently dropped. overrideAccess: true, }); broadcast("game-event", { type: event.type, actor: event.actor ?? null, targetCollection: event.targetCollection ?? null, targetId: event.targetId ?? null, }); } catch (err) { console.error("[EventLog] Failed to emit event:", err); } }