package com.competition.modules.biz.review.controller;

import com.competition.common.result.Result;
import com.competition.common.util.SecurityUtil;
import com.competition.modules.biz.review.service.AnalyticsService;
import com.competition.security.annotation.RequirePermission;
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.Map;

@Tag(name = "数据分析")
@RestController
@RequestMapping("/analytics")
@RequiredArgsConstructor
public class AnalyticsController {

    private final AnalyticsService analyticsService;

    @GetMapping("/overview")
    @RequirePermission("contest:read")
    @Operation(summary = "数据概览")
    public Result<Map<String, Object>> getOverview(
            @RequestParam(required = false) String timeRange,
            @RequestParam(required = false) Long contestId) {
        Long tenantId = SecurityUtil.getCurrentTenantId();
        return Result.success(analyticsService.getOverview(tenantId, contestId));
    }

    @GetMapping("/review")
    @RequirePermission("contest:read")
    @Operation(summary = "评审分析")
    public Result<Map<String, Object>> getReviewAnalysis(
            @RequestParam(required = false) Long contestId) {
        Long tenantId = SecurityUtil.getCurrentTenantId();
        return Result.success(analyticsService.getReviewAnalysis(tenantId, contestId));
    }
}
