package com.snack.server.module.dashboard.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.snack.server.common.Result;
import com.snack.server.module.dashboard.service.DashboardService;
import com.snack.server.module.dashboard.vo.DashboardStatsVO;
import com.snack.server.module.dashboard.vo.NameValueVO;
import com.snack.server.module.dashboard.vo.SalesTrendVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 仪表盘统计（管理端）
 */
@Tag(name = "仪表盘")
@RestController
@RequestMapping("/api/admin/dashboard")
@RequiredArgsConstructor
public class DashboardController {

    private final DashboardService dashboardService;

    @Operation(summary = "统计卡片：今日订单 / 销售额 / 用户 / 商品")
    @SaCheckLogin
    @GetMapping("/stats")
    public Result<DashboardStatsVO> stats() {
        return Result.ok(dashboardService.stats());
    }

    @Operation(summary = "近 N 天销售趋势")
    @SaCheckLogin
    @GetMapping("/sales-trend")
    public Result<List<SalesTrendVO>> salesTrend(
            @Parameter(description = "天数，默认 7") @RequestParam(defaultValue = "7") Integer days) {
        return Result.ok(dashboardService.salesTrend(days == null ? 7 : days));
    }

    @Operation(summary = "订单状态分布")
    @SaCheckLogin
    @GetMapping("/order-status")
    public Result<List<NameValueVO>> orderStatus() {
        return Result.ok(dashboardService.orderStatus());
    }

    @Operation(summary = "热销商品 Top10")
    @SaCheckLogin
    @GetMapping("/hot-products")
    public Result<List<NameValueVO>> hotProducts() {
        return Result.ok(dashboardService.hotProducts());
    }
}
