package com.lesingle.edu.controller.teacher;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lesingle.edu.common.annotation.RequireRole;
import com.lesingle.edu.common.annotation.Log;
import com.lesingle.edu.common.enums.UserRole;
import com.lesingle.edu.common.mapper.LessonFeedbackMapper;
import com.lesingle.edu.common.response.PageResult;
import com.lesingle.edu.common.response.Result;
import com.lesingle.edu.common.security.SecurityUtils;
import com.lesingle.edu.dto.response.LessonFeedbackResponse;
import com.lesingle.edu.entity.LessonFeedback;
import com.lesingle.edu.service.TeacherFeedbackService;
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;

/**
 * 教师端 - 反馈管理
 */
@Tag(name = "教师端 - 反馈管理", description = "教师端反馈 API")
@RestController
@RequestMapping("/api/v1/teacher/feedbacks")
@RequiredArgsConstructor
@RequireRole(UserRole.TEACHER)
public class TeacherFeedbackController {

    private final TeacherFeedbackService teacherFeedbackService;
    private final LessonFeedbackMapper lessonFeedbackMapper;

    @GetMapping
    @Operation(summary = "获取反馈列表")
    public Result<PageResult<LessonFeedbackResponse>> getFeedbacks(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        Long teacherId = SecurityUtils.getCurrentUserId();
        Page<LessonFeedback> page = teacherFeedbackService.getTeacherFeedbacks(teacherId, pageNum, pageSize);
        List<LessonFeedbackResponse> voList = lessonFeedbackMapper.toVO(page.getRecords());
        return Result.success(PageResult.of(voList, page.getTotal(), page.getCurrent(), page.getSize()));
    }

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