package com.reading.platform.controller.school;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.reading.platform.common.annotation.RequireRole;
import com.reading.platform.common.enums.UserRole;
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/school/feedbacks")
@RequiredArgsConstructor
@RequireRole(UserRole.SCHOOL)
public class SchoolFeedbackController {

    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 teacherId,
            @RequestParam(required = false) String lessonId) {
        String tenantId = SecurityUtils.getCurrentTenantId();
        Page<LessonFeedback> page = lessonFeedbackService.getFeedbacksByTenantId(
                tenantId, pageNum, pageSize, teacherId, lessonId);
        return Result.success(PageResult.of(page));
    }

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

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