import type { UploadMediaResult } from '@core/media/application/use-cases/UploadMediaUseCase';
import type { UploadMediaOutputDTO } from '../dtos/UploadMediaOutputDTO';

type UploadMediaResponseModel = UploadMediaOutputDTO;

export class UploadMediaPresenter {
  private model: UploadMediaResponseModel | null = null;

  reset(): void {
    this.model = null;
  }

  transform(result: UploadMediaResult): UploadMediaResponseModel {
    const model: UploadMediaResponseModel = {
      success: true,
      mediaId: result.mediaId,
    };
    
    if (result.url !== undefined) {
      model.url = result.url;
    }
    
    this.model = model;
    return model;
  }

  getResponseModel(): UploadMediaResponseModel | null {
    return this.model;
  }

  get responseModel(): UploadMediaResponseModel {
    if (!this.model) throw new Error('Presenter not presented');
    return this.model;
  }
}