import type { MediaApiClient } from '../../api/media/MediaApiClient';
import type { MediaPresenter } from '../../presenters/MediaPresenter';
import type { UploadMediaInputDto, GetMediaOutputDto, DeleteMediaOutputDto } from '../../dtos';
import type { MediaViewModel, UploadMediaViewModel, DeleteMediaViewModel } from '../../view-models';

/**
 * Media Service
 *
 * Orchestrates media operations by coordinating API calls and presentation logic.
 * All dependencies are injected via constructor.
 */
export class MediaService {
  constructor(
    private readonly apiClient: MediaApiClient,
    private readonly presenter: MediaPresenter
  ) {}

  /**
   * Upload media file with presentation transformation
   */
  async uploadMedia(input: UploadMediaInputDto): Promise<UploadMediaViewModel> {
    try {
      const dto = await this.apiClient.uploadMedia(input);
      return this.presenter.presentUpload(dto);
    } catch (error) {
      throw error;
    }
  }

  /**
   * Get media by ID with presentation transformation
   */
  async getMedia(mediaId: string): Promise<MediaViewModel> {
    try {
      const dto = await this.apiClient.getMedia(mediaId);
      return this.presenter.presentMedia(dto);
    } catch (error) {
      throw error;
    }
  }

  /**
   * Delete media by ID with presentation transformation
   */
  async deleteMedia(mediaId: string): Promise<DeleteMediaViewModel> {
    try {
      const dto = await this.apiClient.deleteMedia(mediaId);
      return this.presenter.presentDelete(dto);
    } catch (error) {
      throw error;
    }
  }
}