import { Controller, Post, Body, Res, HttpStatus } from '@nestjs/common';
import type { Response } from 'express';
import type { RecordPageViewInputDTO } from './dtos/RecordPageViewInputDTO';
import type { RecordPageViewOutputDTO } from './dtos/RecordPageViewOutputDTO';
import type { RecordEngagementInputDTO } from './dtos/RecordEngagementInputDTO';
import type { RecordEngagementOutputDTO } from './dtos/RecordEngagementOutputDTO';
import { AnalyticsService } from './AnalyticsService';

type RecordPageViewInput = RecordPageViewInputDTO;
type RecordPageViewOutput = RecordPageViewOutputDTO;
type RecordEngagementInput = RecordEngagementInputDTO;
type RecordEngagementOutput = RecordEngagementOutputDTO;

@Controller('analytics')
export class AnalyticsController {
  constructor(
    private readonly analyticsService: AnalyticsService,
  ) {}

  @Post('page-view')
  async recordPageView(
    @Body() input: RecordPageViewInput,
    @Res() res: Response,
  ): Promise<void> {
    const output: RecordPageViewOutput = await this.analyticsService.recordPageView(input);
    res.status(HttpStatus.CREATED).json(output);
  }

  @Post('engagement')
  async recordEngagement(
    @Body() input: RecordEngagementInput,
    @Res() res: Response,
  ): Promise<void> {
    const output: RecordEngagementOutput = await this.analyticsService.recordEngagement(input);
    res.status(HttpStatus.CREATED).json(output);
  }
}
