package com.reading.platform.controller.school;

import com.reading.platform.common.annotation.RequireRole;
import com.reading.platform.common.enums.UserRole;
import com.reading.platform.common.response.Result;
import com.reading.platform.common.security.SecurityUtils;
import com.reading.platform.dto.response.*;
import com.reading.platform.service.SchoolReportService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学校报告接口（学校管理员专用）
 */
@Tag(name = "学校 - 报告", description = "数据报告接口（学校管理员专用）")
@RestController
@RequestMapping("/api/v1/school/reports")
@RequiredArgsConstructor
@RequireRole(UserRole.SCHOOL)
public class SchoolReportController {

    private final SchoolReportService schoolReportService;

    @Operation(summary = "获取整体统计报告")
    @GetMapping("/overview")
    public Result<SchoolOverviewStatsResponse> getOverviewReport() {
        String tenantId = SecurityUtils.getCurrentTenantId();
        return Result.success(schoolReportService.getOverviewStats(tenantId));
    }

    @Operation(summary = "获取教师统计报告")
    @GetMapping("/teachers")
    public Result<List<TeacherStatsReportResponse>> getTeacherReport() {
        String tenantId = SecurityUtils.getCurrentTenantId();
        return Result.success(schoolReportService.getTeacherStats(tenantId));
    }

    @Operation(summary = "获取课程统计报告")
    @GetMapping("/courses")
    public Result<List<CourseStatsReportResponse>> getCourseReport() {
        String tenantId = SecurityUtils.getCurrentTenantId();
        return Result.success(schoolReportService.getCourseStats(tenantId));
    }

    @Operation(summary = "获取学生统计报告")
    @GetMapping("/students")
    public Result<List<StudentStatsReportResponse>> getStudentReport(
            @RequestParam(required = false) String classId) {
        String tenantId = SecurityUtils.getCurrentTenantId();
        return Result.success(schoolReportService.getStudentStats(tenantId, classId));
    }

    @Operation(summary = "获取课时趋势（近 6 个月）")
    @GetMapping("/lesson-trend")
    public Result<List<LessonTrendDataPoint>> getLessonTrend(
            @RequestParam(value = "months", required = false, defaultValue = "6") Integer months) {
        String tenantId = SecurityUtils.getCurrentTenantId();
        return Result.success(schoolReportService.getLessonTrend(tenantId, months));
    }
}
