/**
 * TeamStandingsPresenter - Pure data transformer
 * Transforms API response to view model without DI dependencies.
 */

import { apiClient } from '@/lib/apiClient';

export interface TeamLeagueStandingViewModel {
  leagueId: string;
  leagueName: string;
  position: number;
  points: number;
  wins: number;
  racesCompleted: number;
}

export interface TeamStandingsViewModel {
  standings: TeamLeagueStandingViewModel[];
}

/**
 * Compute team standings across the given leagues for a team.
 * This would need a dedicated API endpoint for team standings.
 * For now, returns empty standings - the API should provide this data.
 * @param teamId - The team ID (will be used when API supports team standings)
 * @param leagueIds - List of league IDs to fetch standings for
 */
export async function loadTeamStandings(
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  teamId: string,
  leagueIds: string[],
): Promise<TeamStandingsViewModel> {
  // In the new architecture, team standings should come from API
  // For now, fetch each league's standings and aggregate
  const teamStandings: TeamLeagueStandingViewModel[] = [];

  for (const leagueId of leagueIds) {
    try {
      const standings = await apiClient.leagues.getStandings(leagueId);
      
      // Since we don't have team-specific standings from API yet,
      // this is a placeholder that returns basic data
      teamStandings.push({
        leagueId,
        leagueName: `League ${leagueId}`, // Would need from API
        position: 0,
        points: 0,
        wins: 0,
        racesCompleted: standings.standings.length > 0 ? 1 : 0,
      });
    } catch {
      // Skip leagues that fail to load
    }
  }

  return { standings: teamStandings };
}