package top.tqx.demo_1.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.tqx.demo_1.dto.ReportResponse;
import top.tqx.demo_1.service.ReportService;

import java.util.HashMap;
import java.util.Map;

@Tag(name = "报告管理", description = "反馈统计报告相关接口")
@RestController
@RequestMapping("/report")
@Slf4j
public class ReportController {

    @Autowired
    private ReportService reportService;

    @Operation(summary = "获取周报", description = "获取最近一周的反馈统计报告")
    @GetMapping("/weekly")
    public Map<String, Object> getWeeklyReport() {
        Map<String, Object> result = new HashMap<>();
        try {
            log.info("获取周报");
            ReportResponse response = reportService.getWeeklyReport();
            result.put("success", response.getSuccess());
            result.put("data", response.getReport());
        } catch (Exception e) {
            log.error("获取周报失败", e);
            result.put("success", false);
            result.put("message", "获取周报失败: " + e.getMessage());
        }
        return result;
    }

    @Operation(summary = "获取月报", description = "获取最近一个月的反馈统计报告")
    @GetMapping("/monthly")
    public Map<String, Object> getMonthlyReport() {
        Map<String, Object> result = new HashMap<>();
        try {
            log.info("获取月报");
            ReportResponse response = reportService.getMonthlyReport();
            result.put("success", response.getSuccess());
            result.put("data", response.getReport());
        } catch (Exception e) {
            log.error("获取月报失败", e);
            result.put("success", false);
            result.put("message", "获取月报失败: " + e.getMessage());
        }
        return result;
    }
}
