package com.ruoyi.tjfx.controller;

import com.ruoyi.tjfx.entity.*;
import com.ruoyi.tjfx.service.ReportService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.tjfx.common.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/reports")
public class ReportController {

    @Autowired
    private ReportService reportService;

    // 1. 整体销售分析
    @GetMapping("/overall-analysis")
    public ApiResponse<OverallAnalysisVO> overallAnalysis(
        @RequestParam String startDate,
        @RequestParam String endDate,
        @RequestParam(required = false) String category,
        @RequestParam(required = false) String categorySpecs,
        @RequestParam(required = false) String customer,
        @RequestParam(required = false) String shop,
        @RequestParam(required = false) String brand,
        @RequestParam(required = false) String productCode
    ) {
        return ApiResponse.success(reportService.overallAnalysis(
            startDate, endDate, category, categorySpecs, customer, shop, brand, productCode
        ), "获取整体销售分析数据成功");
    }

    // 2. 单品销售分析
    @GetMapping("/product-analysis")
    public ApiResponse<ProductAnalysisVO> productAnalysis(
        @RequestParam String startDate,
        @RequestParam String endDate,
        @RequestParam String productCode
    ) {
        return ApiResponse.success(reportService.productAnalysis(startDate, endDate, productCode), "获取单品销售分析数据成功");
    }

    // 3. 店铺销售分析
    @GetMapping("/shop-analysis")
    public ApiResponse<ShopAnalysisVO> shopAnalysis(
        @RequestParam String startDate,
        @RequestParam String endDate,
        @RequestParam(required = false) String shop
    ) {
        return ApiResponse.success(reportService.shopAnalysis(startDate, endDate, shop), "获取店铺销售分析数据成功");
    }

    // 4. 分类销售分析
    @GetMapping("/category-analysis")
    public ApiResponse<CategoryAnalysisVO> categoryAnalysis(
        @RequestParam String startDate,
        @RequestParam String endDate,
        @RequestParam(required = false) String category
    ) {
        return ApiResponse.success(reportService.categoryAnalysis(startDate, endDate, category), "获取分类销售分析数据成功");
    }

    // 5. 筛选选项
    @GetMapping("/filter-options")
    public ApiResponse<FilterOptionsVO> filterOptions() {
        return ApiResponse.success(reportService.filterOptions(), "获取筛选选项成功");
    }

    // 6. 商品编码联想
    @GetMapping("/product-code-suggestions")
    public ApiResponse<List<ProductCodeSuggestionVO>> productCodeSuggestions(@RequestParam String keyword) {
        return ApiResponse.success(reportService.productCodeSuggestions(keyword), "获取商品编码联想数据成功");
    }
}
