import { Controller, Get, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard, Roles, RolesGuard, UserRole } from '@genex/common';
import { AdminAnalyticsService } from '../../../application/services/admin-analytics.service';

@ApiTags('Admin - User Analytics')
@Controller('admin/analytics/users')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.ADMIN)
@ApiBearerAuth()
export class AdminAnalyticsController {
  constructor(private readonly analyticsService: AdminAnalyticsService) {}

  @Get('stats')
  @ApiOperation({ summary: 'Get user summary stats (total, DAU, MAU, new this week)' })
  async getUserStats() {
    const data = await this.analyticsService.getUserStats();
    return { code: 0, data };
  }

  @Get('growth-trend')
  @ApiOperation({ summary: 'Get 30-day user registration trend' })
  async getGrowthTrend() {
    const data = await this.analyticsService.getGrowthTrend();
    return { code: 0, data };
  }

  @Get('kyc-distribution')
  @ApiOperation({ summary: 'Get KYC level distribution' })
  async getKycDistribution() {
    const data = await this.analyticsService.getKycDistribution();
    return { code: 0, data };
  }

  @Get('geo-distribution')
  @ApiOperation({ summary: 'Get geographic distribution of users' })
  async getGeoDistribution() {
    const data = await this.analyticsService.getGeoDistribution();
    return { code: 0, data };
  }

  @Get('cohort-retention')
  @ApiOperation({ summary: 'Get weekly cohort retention analysis' })
  async getCohortRetention() {
    const data = await this.analyticsService.getCohortRetention();
    return { code: 0, data };
  }

  @Get('segments')
  @ApiOperation({ summary: 'Get user segmentation by activity level' })
  async getUserSegments() {
    const data = await this.analyticsService.getUserSegments();
    return { code: 0, data };
  }
}
