import { LeaguesApiClient } from './leagues/LeaguesApiClient';
import { RacesApiClient } from './races/RacesApiClient';
import { DriversApiClient } from './drivers/DriversApiClient';
import { TeamsApiClient } from './teams/TeamsApiClient';
import { SponsorsApiClient } from './sponsors/SponsorsApiClient';
import { MediaApiClient } from './media/MediaApiClient';
import { AnalyticsApiClient } from './analytics/AnalyticsApiClient';
import { AuthApiClient } from './auth/AuthApiClient';
import { PaymentsApiClient } from './payments/PaymentsApiClient';

/**
 * Main API Client
 *
 * Orchestrates all domain-specific API clients with consistent configuration.
 */
export class ApiClient {
  public readonly leagues: LeaguesApiClient;
  public readonly races: RacesApiClient;
  public readonly drivers: DriversApiClient;
  public readonly teams: TeamsApiClient;
  public readonly sponsors: SponsorsApiClient;
  public readonly media: MediaApiClient;
  public readonly analytics: AnalyticsApiClient;
  public readonly auth: AuthApiClient;
  public readonly payments: PaymentsApiClient;

  constructor(baseUrl: string) {
    this.leagues = new LeaguesApiClient(baseUrl);
    this.races = new RacesApiClient(baseUrl);
    this.drivers = new DriversApiClient(baseUrl);
    this.teams = new TeamsApiClient(baseUrl);
    this.sponsors = new SponsorsApiClient(baseUrl);
    this.media = new MediaApiClient(baseUrl);
    this.analytics = new AnalyticsApiClient(baseUrl);
    this.auth = new AuthApiClient(baseUrl);
    this.payments = new PaymentsApiClient(baseUrl);
  }
}

// ============================================================================
// Singleton Instance
// ============================================================================

const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3001';

export const api = new ApiClient(API_BASE_URL);