import { Controller, Get, Query, UseGuards } from '@nestjs/common';
import { AdminStatsService } from './admin-stats.service';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import { RolesGuard } from '../common/guards/roles.guard';
import { Roles } from '../common/decorators/roles.decorator';

@Controller('admin/stats')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
export class AdminStatsController {
  constructor(private readonly statsService: AdminStatsService) {}

  @Get()
  async getStats() {
    return this.statsService.getStats();
  }

  @Get('trend')
  async getTrendData() {
    return this.statsService.getTrendData();
  }

  @Get('tenants/active')
  async getActiveTenants(@Query('limit') limit?: string) {
    const limitNum = limit ? parseInt(limit, 10) : 5;
    return this.statsService.getActiveTenants(limitNum);
  }

  @Get('courses/popular')
  async getPopularCourses(@Query('limit') limit?: string) {
    const limitNum = limit ? parseInt(limit, 10) : 5;
    return this.statsService.getPopularCourses(limitNum);
  }

  @Get('activities')
  async getRecentActivities(@Query('limit') limit?: string) {
    const limitNum = limit ? parseInt(limit, 10) : 10;
    return this.statsService.getRecentActivities(limitNum);
  }
}
