import { AnalyticsApiClient } from '../../api/analytics/AnalyticsApiClient'; import { RecordPageViewOutputDTO, RecordEngagementOutputDTO } from '../../types/generated'; import { RecordPageViewInputViewModel } from '../../view-models/RecordPageViewInputViewModel'; import { RecordEngagementInputViewModel } from '../../view-models/RecordEngagementInputViewModel'; /** * Analytics Service * * Orchestrates analytics operations by coordinating API calls. * All dependencies are injected via constructor. */ export class AnalyticsService { constructor( private readonly apiClient: AnalyticsApiClient ) {} /** * Record a page view */ async recordPageView(input: RecordPageViewInputViewModel): Promise { const apiInput: { path: string; userId?: string } = { path: input.path, }; if (input.userId) { apiInput.userId = input.userId; } return await this.apiClient.recordPageView(apiInput); } /** * Record an engagement event */ async recordEngagement(input: RecordEngagementInputViewModel): Promise { const apiInput: { eventType: string; userId?: string; metadata?: Record } = { eventType: input.eventType, }; if (input.userId) { apiInput.userId = input.userId; } if (input.metadata) { apiInput.metadata = input.metadata; } return await this.apiClient.recordEngagement(apiInput); } }