package com.reading.platform.controller.teacher;

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.TeacherDashboardService;
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/teacher/dashboard")
@RequiredArgsConstructor
@RequireRole(UserRole.TEACHER)
public class TeacherDashboardController {

    private final TeacherDashboardService teacherDashboardService;

    @Operation(summary = "获取教师仪表盘概览")
    @GetMapping
    public Result<TeacherDashboardResponse> getDashboard() {
        String teacherId = SecurityUtils.getCurrentUserId();
        String tenantId = SecurityUtils.getCurrentTenantId();
        return Result.success(teacherDashboardService.getDashboard(teacherId, tenantId));
    }

    @Operation(summary = "获取今天课时")
    @GetMapping("/today")
    public Result<List<LessonSimpleResponse>> getTodayLessons() {
        String teacherId = SecurityUtils.getCurrentUserId();
        String tenantId = SecurityUtils.getCurrentTenantId();
        return Result.success(teacherDashboardService.getTodayLessons(teacherId, tenantId));
    }

    @Operation(summary = "获取本周课时")
    @GetMapping("/weekly")
    public Result<List<LessonSimpleResponse>> getWeeklyLessons() {
        String teacherId = SecurityUtils.getCurrentUserId();
        String tenantId = SecurityUtils.getCurrentTenantId();
        return Result.success(teacherDashboardService.getWeeklyLessons(teacherId, tenantId));
    }

    @Operation(summary = "获取推荐课程")
    @GetMapping("/recommend")
    public Result<List<RecommendedCourseResponse>> getRecommendedCourses() {
        String tenantId = SecurityUtils.getCurrentTenantId();
        return Result.success(teacherDashboardService.getRecommendedCourses(tenantId));
    }

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

    @Operation(summary = "获取课程使用情况")
    @GetMapping("/course-usage")
    public Result<List<CourseUsageItemResponse>> getCourseUsage() {
        String teacherId = SecurityUtils.getCurrentUserId();
        return Result.success(teacherDashboardService.getCourseUsage(teacherId));
    }
}
