export type WorkbenchRealtimeDecodeStatus = "accepted" | "invalid-json" | "not-object";

export interface WorkbenchRealtimeDecodedFrame {
  payload: Record<string, unknown> | null;
  status: WorkbenchRealtimeDecodeStatus;
}

export function decodeWorkbenchRealtimeEventFrame(raw: string): WorkbenchRealtimeDecodedFrame {
  try {
    const value = JSON.parse(raw);
    return value && typeof value === "object" && !Array.isArray(value)
      ? { payload: value as Record<string, unknown>, status: "accepted" }
      : { payload: null, status: "not-object" };
  } catch {
    return { payload: null, status: "invalid-json" };
  }
}
