import { Module } from '@nestjs/common';

import { LoggingModule } from '../../domain/logging/LoggingModule';

import type { Logger } from '@core/shared/application/Logger';

import type { IEngagementRepository } from '@core/analytics/domain/repositories/IEngagementRepository';
import type { IAnalyticsSnapshotRepository } from '@core/analytics/domain/repositories/IAnalyticsSnapshotRepository';
import type { IPageViewRepository } from '@core/analytics/application/repositories/IPageViewRepository';

import { InMemoryAnalyticsSnapshotRepository } from '@adapters/analytics/persistence/inmemory/InMemoryAnalyticsSnapshotRepository';
import { InMemoryEngagementRepository } from '@adapters/analytics/persistence/inmemory/InMemoryEngagementRepository';
import { InMemoryPageViewRepository } from '@adapters/analytics/persistence/inmemory/InMemoryPageViewRepository';

import {
  ANALYTICS_ENGAGEMENT_REPOSITORY_TOKEN,
  ANALYTICS_PAGE_VIEW_REPOSITORY_TOKEN,
  ANALYTICS_SNAPSHOT_REPOSITORY_TOKEN,
} from '../analytics/AnalyticsPersistenceTokens';

@Module({
  imports: [LoggingModule],
  providers: [
    {
      provide: ANALYTICS_PAGE_VIEW_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): IPageViewRepository => new InMemoryPageViewRepository(logger),
      inject: ['Logger'],
    },
    {
      provide: ANALYTICS_ENGAGEMENT_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): IEngagementRepository => new InMemoryEngagementRepository(logger),
      inject: ['Logger'],
    },
    {
      provide: ANALYTICS_SNAPSHOT_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): IAnalyticsSnapshotRepository => new InMemoryAnalyticsSnapshotRepository(logger),
      inject: ['Logger'],
    },
  ],
  exports: [
    ANALYTICS_PAGE_VIEW_REPOSITORY_TOKEN,
    ANALYTICS_ENGAGEMENT_REPOSITORY_TOKEN,
    ANALYTICS_SNAPSHOT_REPOSITORY_TOKEN,
  ],
})
export class InMemoryAnalyticsPersistenceModule {}