package com.campus.activity.controller;

import com.campus.activity.common.Result;
import com.campus.activity.service.StatisticsService;
import com.campus.activity.vo.ActivityStatisticsVO;
import com.campus.activity.vo.OverviewStatisticsVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Tag(name = "统计模块", description = "数据统计与导出相关接口")
@RestController
@RequestMapping("/api/v1/statistics")
@RequiredArgsConstructor
public class StatisticsController {

    private final StatisticsService statisticsService;

    @Operation(summary = "获取活动统计数据（管理员）")
    @GetMapping("/activity/{activityId}")
    @PreAuthorize("hasRole('ADMIN')")
    public Result<ActivityStatisticsVO> getActivityStatistics(@PathVariable Long activityId) {
        ActivityStatisticsVO statistics = statisticsService.getActivityStatistics(activityId);
        return Result.success(statistics);
    }

    @Operation(summary = "导出活动数据（管理员）")
    @GetMapping("/activity/{activityId}/export")
    @PreAuthorize("hasRole('ADMIN')")
    public ResponseEntity<byte[]> exportActivityData(
            @PathVariable Long activityId,
            @RequestParam(defaultValue = "csv") String format) {
        return statisticsService.exportActivityData(activityId, format);
    }

    @Operation(summary = "获取总体统计（管理员）")
    @GetMapping("/overview")
    @PreAuthorize("hasRole('ADMIN')")
    public Result<OverviewStatisticsVO> getOverviewStatistics() {
        OverviewStatisticsVO statistics = statisticsService.getOverviewStatistics();
        return Result.success(statistics);
    }
}