import { BaseApiClient } from '../base/BaseApiClient';
import type {
  RequestAvatarGenerationInputDto,
  RequestAvatarGenerationOutputDto,
  UploadMediaInputDto,
  UploadMediaOutputDto,
  GetMediaOutputDto,
  DeleteMediaOutputDto,
  GetAvatarOutputDto,
  UpdateAvatarInputDto,
  UpdateAvatarOutputDto,
} from '../../dtos';

/**
 * Media API Client
 *
 * Handles all media-related API operations.
 */
export class MediaApiClient extends BaseApiClient {
  /** Upload media file */
  uploadMedia(input: UploadMediaInputDto): Promise<UploadMediaOutputDto> {
    const formData = new FormData();
    formData.append('file', input.file);
    formData.append('type', input.type);
    if (input.category) {
      formData.append('category', input.category);
    }
    return this.post<UploadMediaOutputDto>('/media/upload', formData);
  }

  /** Get media by ID */
  getMedia(mediaId: string): Promise<GetMediaOutputDto> {
    return this.get<GetMediaOutputDto>(`/media/${mediaId}`);
  }

  /** Delete media by ID */
  deleteMedia(mediaId: string): Promise<DeleteMediaOutputDto> {
    return this.delete<DeleteMediaOutputDto>(`/media/${mediaId}`);
  }

  /** Request avatar generation */
  requestAvatarGeneration(input: RequestAvatarGenerationInputDto): Promise<RequestAvatarGenerationOutputDto> {
    return this.post<RequestAvatarGenerationOutputDto>('/media/avatar/generate', input);
  }

  /** Get avatar for driver */
  getAvatar(driverId: string): Promise<GetAvatarOutputDto> {
    return this.get<GetAvatarOutputDto>(`/media/avatar/${driverId}`);
  }

  /** Update avatar for driver */
  updateAvatar(input: UpdateAvatarInputDto): Promise<UpdateAvatarOutputDto> {
    return this.put<UpdateAvatarOutputDto>(`/media/avatar/${input.driverId}`, { avatarUrl: input.avatarUrl });
  }
}