package com.xdap.self_development.controller;

import com.definesys.mpaas.common.http.Response;
import com.xdap.self_development.controller.request.ReportRequest;
import com.xdap.self_development.domain.pojo.DataEntryEngineModelPojo;
import com.xdap.self_development.domain.view.AnalysisModelParamterViewAndParam;
import com.xdap.self_development.service.AnalysisCommonParametersService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 数据分析公共控制器
 * 提供数据分析相关的通用功能，包括模型参数查询、可用参数获取、报表展示等功能
 *
 * @version 1.0
 * @since 2025
 */
@RestController
@RequestMapping("/custom/analysis")
public class AnalysisCommonController {
    @Resource
    AnalysisCommonParametersService analysisCommonParametersService;

    /**
     * 获取可用参数
     *
     * @return 可用参数列表
     */
    @GetMapping("/getAvailableParameters")
    public Response getAvailableParameters(
            @RequestParam(required = false) String userId
    ) {
        List<String> lists = analysisCommonParametersService.getAvailableParameters(userId);
        return Response.ok().data(lists);
    }

    /**
     * 统计分析图表
     *
     * @param models 模型列表
     * @return 分析模型参数视图和参数
     */
    @PostMapping("/showReport")
    public Response showReport(@NotEmpty @RequestBody List<String> models) {
        AnalysisModelParamterViewAndParam andParam = analysisCommonParametersService.showReport(models);
        return Response.ok().data(andParam);
    }

    /**
     * 模糊查询机型
     *
     * @param request 报表请求对象
     * @return 引擎模型数据项列表
     */
    @PostMapping("/selectModelByLike")
    public Response selectModelByLike(
            @RequestBody ReportRequest request
    ) {
        List<DataEntryEngineModelPojo> lists = analysisCommonParametersService.selectModelByLike(request);
        return Response.ok().data(lists);
    }

}
