import { DriversApiClient } from "@/lib/api/drivers/DriversApiClient"; import { CompleteOnboardingInputDTO } from "@/lib/types/generated/CompleteOnboardingInputDTO"; import { DriverProfileDTO } from "@/lib/types/generated/DriverProfileDTO"; import type { DriverDTO } from "@/lib/types/generated/DriverDTO"; import { CompleteOnboardingViewModel } from "@/lib/view-models/CompleteOnboardingViewModel"; import { DriverLeaderboardViewModel } from "@/lib/view-models/DriverLeaderboardViewModel"; import { DriverViewModel } from "@/lib/view-models/DriverViewModel"; import { DriverProfileViewModel } from "@/lib/view-models/DriverProfileViewModel"; /** * Driver Service * * Orchestrates driver operations by coordinating API calls and view model creation. * All dependencies are injected via constructor. */ export class DriverService { constructor( private readonly apiClient: DriversApiClient ) {} /** * Get driver leaderboard with view model transformation */ async getDriverLeaderboard(): Promise { const dto = await this.apiClient.getLeaderboard(); return new DriverLeaderboardViewModel(dto); } /** * Complete driver onboarding with view model transformation */ async completeDriverOnboarding(input: CompleteOnboardingInputDTO): Promise { const dto = await this.apiClient.completeOnboarding(input); return new CompleteOnboardingViewModel(dto); } /** * Get current driver with view model transformation */ async getCurrentDriver(): Promise { const dto = await this.apiClient.getCurrent(); if (!dto) { return null; } return new DriverViewModel(dto); } /** * Get driver profile with full details and view model transformation */ async getDriverProfile(driverId: string): Promise { const dto = await this.apiClient.getDriverProfile(driverId); return new DriverProfileViewModel(dto); } /** * Update current driver profile with view model transformation */ async updateProfile(updates: { bio?: string; country?: string }): Promise { const dto = await this.apiClient.updateProfile(updates); // After updating, get the full profile again to return updated view model return this.getDriverProfile(dto.id); } /** * Find driver by ID */ async findById(id: string): Promise { return this.apiClient.getDriver(id); } /** * Find multiple drivers by IDs */ async findByIds(ids: string[]): Promise { const drivers = await Promise.all(ids.map(id => this.apiClient.getDriver(id))); return drivers.filter((d): d is DriverDTO => d !== null); } }