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

export class GetAnalyticsMetricsPresenter {
  private model: GetAnalyticsMetricsOutputDTO | null = null;

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

  transform(result: GetAnalyticsMetricsOutput): GetAnalyticsMetricsOutputDTO {
    this.model = {
      pageViews: result.pageViews,
      uniqueVisitors: result.uniqueVisitors,
      averageSessionDuration: result.averageSessionDuration,
      bounceRate: result.bounceRate,
    };
    return this.model;
  }

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

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