import {
  type AgentSummaryViewModel,
  DataClient,
  type PlatformSummaryViewModel,
  SortableFields,
  type TopStrategiesByRoiViewModel,
  type TopStrategiesViewModel
} from '../generated/ManagingApi'

export interface PlatformData {
  platform: PlatformSummaryViewModel
  topStrategies: TopStrategiesViewModel
  topStrategiesByRoi: TopStrategiesByRoiViewModel
  topAgentsByPnL: AgentSummaryViewModel[]
}

export const fetchPlatformData = async (apiUrl: string): Promise<PlatformData> => {
  const client = new DataClient({}, apiUrl)
  
  // Fetch all platform data in parallel
  const [platform, topStrategies, topStrategiesByRoi, agentIndexResponse] = await Promise.all([
    client.data_GetPlatformSummary(),
    client.data_GetTopStrategies(),
    client.data_GetTopStrategiesByRoi(),
    client.data_GetAgentIndexPaginated(1, 3, SortableFields.NetPnL, 'desc', null) // Get top 3 agents by NetPnL
  ])
  
  return {
    platform,
    topStrategies,
    topStrategiesByRoi,
    topAgentsByPnL: agentIndexResponse.agentSummaries || []
  }
}
