import type { DeleteMediaOutputDTO } from '../../types/generated/DeleteMediaOutputDTO';
import type { GetAvatarOutputDTO } from '../../types/generated/GetAvatarOutputDTO';
import type { GetMediaOutputDTO } from '../../types/generated/GetMediaOutputDTO';
import type { RequestAvatarGenerationInputDTO } from '../../types/generated/RequestAvatarGenerationInputDTO';
import type { RequestAvatarGenerationOutputDTO } from '../../types/generated/RequestAvatarGenerationOutputDTO';
import type { UpdateAvatarInputDTO } from '../../types/generated/UpdateAvatarInputDTO';
import type { UpdateAvatarOutputDTO } from '../../types/generated/UpdateAvatarOutputDTO';
import type { UploadMediaOutputDTO } from '../../types/generated/UploadMediaOutputDTO';
import type { ValidateFaceInputDTO } from '../../types/generated/ValidateFaceInputDTO';
import type { ValidateFaceOutputDTO } from '../../types/generated/ValidateFaceOutputDTO';
import { BaseApiClient } from '../base/BaseApiClient';

/**
 * Media API Client
 *
 * Handles all media-related API operations.
 */
export class MediaApiClient extends BaseApiClient {
  /** Upload media file */
  uploadMedia(input: { file: File; type: string; category?: string }): 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 });
  }

  /** Validate face photo for avatar generation */
  validateFacePhoto(input: ValidateFaceInputDTO): Promise<ValidateFaceOutputDTO> {
    return this.post<ValidateFaceOutputDTO>('/media/avatar/validate-face', input);
  }
}
