import { Controller, Get, Query } from '@nestjs/common';
import {
  EngagementService,
  EngagementOverview,
  PageMetrics,
  EventMetrics,
  ScrollDepthMetrics,
  UserFlow,
} from './engagement.service';
import {
  EngagementQueryDto,
  PageQueryDto,
  EventQueryDto,
  ScrollDepthQueryDto,
  UserFlowQueryDto,
} from './dto/engagement-query.dto';

@Controller('engagement')
export class EngagementController {
  constructor(private readonly engagementService: EngagementService) {}

  /**
   * Get engagement overview
   * GET /engagement/overview?startDate=2024-01-01&endDate=2024-01-31
   */
  @Get('overview')
  async getOverview(@Query() query: EngagementQueryDto): Promise<EngagementOverview> {
    return this.engagementService.getOverview(query);
  }

  /**
   * Get page performance
   * GET /engagement/pages?startDate=2024-01-01&endDate=2024-01-31&sortBy=views
   */
  @Get('pages')
  async getPages(@Query() query: PageQueryDto): Promise<PageMetrics[]> {
    return this.engagementService.getPages(query);
  }

  /**
   * Get event breakdown
   * GET /engagement/events?startDate=2024-01-01&endDate=2024-01-31&category=click
   */
  @Get('events')
  async getEvents(@Query() query: EventQueryDto): Promise<EventMetrics[]> {
    return this.engagementService.getEvents(query);
  }

  /**
   * Get scroll depth metrics
   * GET /engagement/scroll-depth?startDate=2024-01-01&endDate=2024-01-31&page=/profile
   */
  @Get('scroll-depth')
  async getScrollDepth(@Query() query: ScrollDepthQueryDto): Promise<ScrollDepthMetrics[]> {
    return this.engagementService.getScrollDepth(query);
  }

  /**
   * Get user flow analysis
   * GET /engagement/user-flow?startDate=2024-01-01&endDate=2024-01-31&startPage=/
   */
  @Get('user-flow')
  async getUserFlow(@Query() query: UserFlowQueryDto): Promise<UserFlow[]> {
    return this.engagementService.getUserFlow(query);
  }
}
