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

type UploadMediaResponseModel = UploadMediaOutputDTO;

export class UploadMediaPresenter implements UseCaseOutputPort<UploadMediaResult> {
  private model: UploadMediaResponseModel | null = null;

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

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

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

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