package com.lesingle.edu.controller.admin;

import com.lesingle.edu.common.annotation.RequireRole;
import com.lesingle.edu.common.enums.UserRole;
import com.lesingle.edu.common.response.Result;
import com.lesingle.edu.dto.request.ActiveTenantsQueryRequest;
import com.lesingle.edu.dto.request.PopularCoursesQueryRequest;
import com.lesingle.edu.dto.response.ActiveTenantItemResponse;
import com.lesingle.edu.dto.response.PopularCourseItemResponse;
import com.lesingle.edu.dto.response.StatsResponse;
import com.lesingle.edu.dto.response.StatsTrendResponse;
import com.lesingle.edu.service.StatsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 统计管理控制器（超管端）
 */
@RestController
@RequestMapping("/api/v1/admin/stats")
@RequiredArgsConstructor
@RequireRole(UserRole.ADMIN)
@Tag(name = "超管端 - 统计管理")
public class AdminStatsController {

    private final StatsService statsService;

    @GetMapping
    @Operation(summary = "获取统计数据")
    public Result<StatsResponse> getStats() {
        return Result.success(statsService.getStats());
    }

    @GetMapping("/trend")
    @Operation(summary = "获取趋势数据")
    public Result<StatsTrendResponse> getTrendData() {
        return Result.success(statsService.getTrendData());
    }

    @GetMapping("/tenants/active")
    @Operation(summary = "获取活跃租户")
    public Result<List<ActiveTenantItemResponse>> getActiveTenants(@ModelAttribute ActiveTenantsQueryRequest request) {
        return Result.success(statsService.getActiveTenants(request));
    }

    @GetMapping("/courses/popular")
    @Operation(summary = "获取热门课程")
    public Result<List<PopularCourseItemResponse>> getPopularCourses(@ModelAttribute PopularCoursesQueryRequest request) {
        return Result.success(statsService.getPopularCourses(request));
    }

}