import type { DriversApiClient } from '../../api/drivers/DriversApiClient';
import type { DriversLeaderboardPresenter } from '../../presenters/DriversLeaderboardPresenter';
import type { DriverPresenter } from '../../presenters/DriverPresenter';
import type { CompleteOnboardingPresenter } from '../../presenters/CompleteOnboardingPresenter';
import type { DriverLeaderboardViewModel } from '../../view-models';
import type { DriverViewModel } from '../../view-models/DriverViewModel';
import type { CompleteOnboardingViewModel } from '../../view-models/CompleteOnboardingViewModel';
// Import generated types instead of manual DTOs
import type { CompleteOnboardingInputDTO } from '../../types/api-helpers';

/**
 * Driver Service
 *
 * Orchestrates driver operations by coordinating API calls and presentation logic.
 * All dependencies are injected via constructor.
 */
export class DriverService {
  constructor(
    private readonly apiClient: DriversApiClient,
    private readonly leaderboardPresenter: DriversLeaderboardPresenter,
    private readonly driverPresenter: DriverPresenter,
    private readonly onboardingPresenter: CompleteOnboardingPresenter
  ) {}

  /**
   * Get driver leaderboard with presentation transformation
   */
  async getDriverLeaderboard(): Promise<DriverLeaderboardViewModel> {
    const dto = await this.apiClient.getLeaderboard();
    return this.leaderboardPresenter.present(dto);
  }

  /**
   * Complete driver onboarding with presentation transformation
   */
  async completeDriverOnboarding(input: CompleteOnboardingInputDTO): Promise<CompleteOnboardingViewModel> {
    const dto = await this.apiClient.completeOnboarding(input);
    return this.onboardingPresenter.present(dto);
  }

  /**
   * Get current driver with presentation transformation
   */
  async getCurrentDriver(): Promise<DriverViewModel | null> {
    const dto = await this.apiClient.getCurrent();
    if (!dto) {
      return null;
    }
    return this.driverPresenter.present(dto);
  }
}