import type { MissionControlBridgeStatusResponse } from '@/services/api/missionControl'
import { normalizeExplorerStats, type ExplorerStats } from '@/services/api/stats'
import { fetchPublicJson } from './publicExplorer'

export interface ExplorerTruthContext {
  initialStats: ExplorerStats | null
  initialBridgeStatus: MissionControlBridgeStatusResponse | null
}

export async function fetchExplorerTruthContext(): Promise<ExplorerTruthContext> {
  const [statsResult, bridgeResult] = await Promise.all([
    fetchPublicJson('/api/v2/stats').catch(() => null),
    fetchPublicJson<MissionControlBridgeStatusResponse>('/explorer-api/v1/track1/bridge/status').catch(() => null),
  ])

  return {
    initialStats: statsResult ? normalizeExplorerStats(statsResult as never) : null,
    initialBridgeStatus: bridgeResult,
  }
}
