import { Controller, Get, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiQuery } from '@nestjs/swagger';
import { CohortsService } from './cohorts.service';

@ApiTags('Cohorts')
@Controller('cohorts')
export class CohortsController {
  constructor(private readonly cohortsService: CohortsService) {}

  @Get('retention')
  @ApiOperation({ summary: 'Get retention cohort analysis' })
  @ApiQuery({ name: 'startDate', required: true })
  @ApiQuery({ name: 'endDate', required: true })
  @ApiQuery({ name: 'granularity', required: false, enum: ['day', 'week', 'month'] })
  async getRetentionCohorts(
    @Query('startDate') startDate: string,
    @Query('endDate') endDate: string,
    @Query('granularity') granularity: 'day' | 'week' | 'month' = 'week',
  ) {
    return this.cohortsService.getRetentionCohorts(startDate, endDate, granularity);
  }

  @Get('behavioral')
  @ApiOperation({ summary: 'Get behavioral cohort analysis' })
  async getBehavioralCohorts(
    @Query('startDate') startDate: string,
    @Query('endDate') endDate: string,
    @Query('segmentBy') segmentBy: string,
  ) {
    return this.cohortsService.getBehavioralCohorts(startDate, endDate, segmentBy);
  }
}
