import { injectable, unmanaged } from 'inversify';
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
import { Service } from '@/lib/contracts/services/Service';

@injectable()
export class LeagueWizardService implements Service {
  private readonly apiClient: LeaguesApiClient;

  constructor(@unmanaged() apiClient?: LeaguesApiClient) {
    if (apiClient) {
      this.apiClient = apiClient;
    } else {
      const baseUrl = getWebsiteApiBaseUrl();
      const logger = new ConsoleLogger();
      const errorReporter = new EnhancedErrorReporter(logger);
      this.apiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
    }
  }

  // Add methods as needed by tests
  async createLeague(form: any, ownerId: string): Promise<any> {
    const command = form.toCreateLeagueCommand(ownerId);
    return this.apiClient.create(command);
  }

  async createLeagueFromConfig(form: any, ownerId: string): Promise<any> {
    return this.createLeague(form, ownerId);
  }

  async validateLeagueConfig(input: any): Promise<any> {
    // Mock implementation or call API if available
    return { valid: true };
  }
}
