import { CommandHandler, type ICommandHandler } from '@nestjs/cqrs';
import { type LoggerService } from '@modules/shared';
import { TrackEventCommand } from './track-event.command';

export interface TrackEventResult {
  tracked: boolean;
  eventType: string;
}

@CommandHandler(TrackEventCommand)
export class TrackEventHandler implements ICommandHandler<TrackEventCommand> {
  constructor(private readonly logger: LoggerService) {}

  async execute(command: TrackEventCommand): Promise<TrackEventResult> {
    this.logger.log(
      `Analytics event: ${command.eventType} on ${command.entityType}:${command.entityId}`,
      'TrackEventHandler',
    );

    return {
      tracked: true,
      eventType: command.eventType,
    };
  }
}
