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

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

@CommandHandler(TrackEventCommand)
export class TrackEventHandler implements ICommandHandler<TrackEventCommand> {
  private readonly logger = new Logger(TrackEventHandler.name);

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

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