import type { GetAnalyticsMetricsOutput } from '@core/analytics/application/use-cases/GetAnalyticsMetricsUseCase';
import type { UseCaseOutputPort } from '@core/shared/application';
import type { GetAnalyticsMetricsOutputDTO } from '../dtos/GetAnalyticsMetricsOutputDTO';

export class GetAnalyticsMetricsPresenter implements UseCaseOutputPort<GetAnalyticsMetricsOutput> {
  private model: GetAnalyticsMetricsOutputDTO | null = null;

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

  present(result: GetAnalyticsMetricsOutput): void {
    this.model = {
      pageViews: result.pageViews,
      uniqueVisitors: result.uniqueVisitors,
      averageSessionDuration: result.averageSessionDuration,
      bounceRate: result.bounceRate,
    };
  }

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

  getResponseModel(): GetAnalyticsMetricsOutputDTO {
    if (!this.model) throw new Error('Presenter not presented');
    return this.model;
  }
}
