package com.reading.platform.controller.teacher;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.reading.platform.common.response.PageResult;
import com.reading.platform.common.response.Result;
import com.reading.platform.common.security.SecurityUtils;
import com.reading.platform.entity.LessonFeedback;
import com.reading.platform.service.LessonFeedbackService;
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;
import java.util.Map;
import java.util.ArrayList;

@Tag(name = "教师 - 反馈", description = "课程反馈接口（教师专用）")
@RestController
@RequestMapping("/api/v1/teacher/feedbacks")
@RequiredArgsConstructor
public class TeacherFeedbackController {

    private final LessonFeedbackService lessonFeedbackService;

    @Operation(summary = "获取课程反馈列表")
    @GetMapping
    public Result<PageResult<LessonFeedback>> getFeedbacks(
            @RequestParam(value = "page", required = false) Integer pageNum,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) String lessonId) {
        String teacherId = SecurityUtils.getCurrentUserId();
        Page<LessonFeedback> page = lessonFeedbackService.getFeedbacksByTeacherId(
                teacherId, pageNum, pageSize, lessonId);
        return Result.success(PageResult.of(page));
    }

    @Operation(summary = "获取反馈统计")
    @GetMapping("/stats")
    public Result<Map<String, Object>> getStats() {
        String teacherId = SecurityUtils.getCurrentUserId();
        return Result.success(lessonFeedbackService.getTeacherFeedbackStats(teacherId));
    }

    @Operation(summary = "根据 ID 获取课程反馈")
    @GetMapping("/{id}")
    public Result<LessonFeedback> getFeedback(@PathVariable String id) {
        return Result.success(lessonFeedbackService.getFeedbackById(id));
    }
}
