import { RequestAvatarGenerationInputDTO } from '@/lib/types/generated/RequestAvatarGenerationInputDTO';
import { UpdateAvatarInputDTO } from '@/lib/types/generated/UpdateAvatarInputDTO';
import { AvatarViewModel } from '@/lib/view-models/AvatarViewModel';
import { RequestAvatarGenerationViewModel } from '@/lib/view-models/RequestAvatarGenerationViewModel';
import { UpdateAvatarViewModel } from '@/lib/view-models/UpdateAvatarViewModel';
import type { MediaApiClient } from '../../api/media/MediaApiClient';

/**
 * Avatar Service
 *
 * Orchestrates avatar operations by coordinating API calls and view model creation.
 * All dependencies are injected via constructor.
 */
export class AvatarService {
  constructor(
    private readonly apiClient: MediaApiClient
  ) {}

  /**
   * Request avatar generation with view model transformation
   */
  async requestAvatarGeneration(input: RequestAvatarGenerationInputDTO): Promise<RequestAvatarGenerationViewModel> {
    const dto = await this.apiClient.requestAvatarGeneration(input);
    return new RequestAvatarGenerationViewModel(dto);
  }

  /**
   * Get avatar for driver with view model transformation
   */
  async getAvatar(driverId: string): Promise<AvatarViewModel> {
    const dto = await this.apiClient.getAvatar(driverId);
    // Convert GetAvatarOutputDTO to AvatarDTO format
    const avatarDto = {
      driverId: driverId,
      avatarUrl: dto.avatarUrl
    };
    return new AvatarViewModel(avatarDto);
  }

  /**
   * Update avatar for driver with view model transformation
   */
  async updateAvatar(input: UpdateAvatarInputDTO): Promise<UpdateAvatarViewModel> {
    const dto = await this.apiClient.updateAvatar(input);
    return new UpdateAvatarViewModel(dto);
  }
}