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

import com.lesingle.common.result.Result;
import com.lesingle.common.util.SecurityUtil;
import com.lesingle.modules.biz.review.service.AnalyticsService;
import com.lesingle.modules.sys.service.ISysTenantService;
import com.lesingle.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;
    private final ISysTenantService tenantService;

    @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();
        boolean isSuperTenant = tenantService.isSuperTenant(tenantId);
        return Result.success(analyticsService.getOverview(tenantId, isSuperTenant, contestId, timeRange));
    }

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