import {
  Controller,
  Get,
  Query,
  UseGuards,
  Request,
} from '@nestjs/common';
import { StatsService } from './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('school')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('school')
export class StatsController {
  constructor(private readonly statsService: StatsService) {}

  @Get('stats')
  getStats(@Request() req: any) {
    return this.statsService.getSchoolStats(req.user.tenantId);
  }

  @Get('stats/teachers')
  getActiveTeachers(@Request() req: any, @Query('limit') limit?: string) {
    return this.statsService.getActiveTeachers(
      req.user.tenantId,
      limit ? parseInt(limit, 10) : 5,
    );
  }

  @Get('stats/courses')
  getCourseUsageStats(@Request() req: any) {
    return this.statsService.getCourseUsageStats(req.user.tenantId);
  }

  @Get('stats/activities')
  getRecentActivities(@Request() req: any, @Query('limit') limit?: string) {
    return this.statsService.getRecentActivities(
      req.user.tenantId,
      limit ? parseInt(limit, 10) : 10,
    );
  }

  @Get('stats/lesson-trend')
  getLessonTrend(@Request() req: any, @Query('months') months?: string) {
    return this.statsService.getLessonTrend(
      req.user.tenantId,
      months ? parseInt(months, 10) : 6,
    );
  }

  @Get('stats/course-distribution')
  getCourseDistribution(@Request() req: any) {
    return this.statsService.getCourseDistribution(req.user.tenantId);
  }

  // ==================== 数据报告 API ====================

  @Get('reports/overview')
  getReportOverview(@Request() req: any) {
    return this.statsService.getReportOverview(req.user.tenantId);
  }

  @Get('reports/teachers')
  getTeacherReports(@Request() req: any) {
    return this.statsService.getTeacherReports(req.user.tenantId);
  }

  @Get('reports/courses')
  getCourseReports(@Request() req: any) {
    return this.statsService.getCourseReports(req.user.tenantId);
  }

  @Get('reports/students')
  getStudentReports(@Request() req: any) {
    return this.statsService.getStudentReports(req.user.tenantId);
  }
}
