package com.yfd.platform.modules.algorithm.controller;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.modules.algorithm.domain.AlgorithmParams;
import com.yfd.platform.modules.algorithm.service.IAlgorithmParamsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 算法分类参数
 * 前端控制器
 * </p>
 *
 * @author zhengsl
 * @since 2025-05-13
 */
@RestController
@RequestMapping("/algorithm/algorithm-params")
@Api(value = "AlgorithmParamsController", tags = "算法分类参数")
public class AlgorithmParamsController {

    @Resource
    private IAlgorithmParamsService algorithmParamsService;

    @GetMapping("/getAlgorithmParamsList")
    @ApiOperation("查询算法参数")
    public ResponseResult getAlgorithmParamsList(String algorithmId,String componentId) {
        List<Map<String, Object>> algorithmClassList = algorithmParamsService.getAlgorithmParamsList(algorithmId,componentId);
        return ResponseResult.successData(algorithmClassList);
    }

    @GetMapping("/getAlgorithmParamsNameList")
    @ApiOperation("获取参数名称")
    public ResponseResult getAlgorithmParamsNameList(String algorithmId, String componentId) {
        List<Map<String, Object>> algorithmClassList = algorithmParamsService.getAlgorithmParamsNameList(algorithmId,
                componentId);
        return ResponseResult.successData(algorithmClassList);
    }

    @PostMapping("/addAlgorithmParams")
    @ApiOperation("新增算法参数")
    public ResponseResult addAlgorithmParams(@RequestBody AlgorithmParams algorithmParams) {
        boolean isOK = algorithmParamsService.addAlgorithmParams(algorithmParams);
        if (isOK) {
            return ResponseResult.success();
        } else {
            return ResponseResult.error();
        }
    }

    @PostMapping("/batchAddAlgorithmParams")
    @ApiOperation("批量新增算法参数")
    public ResponseResult batchAddAlgorithmParams(@RequestBody List<AlgorithmParams> algorithmParamsList) {
        boolean isOK = algorithmParamsService.batchAddAlgorithmParams(algorithmParamsList);
        if (isOK) {
            return ResponseResult.success();
        } else {
            return ResponseResult.error();
        }
    }

    @PostMapping("/batchUpdateAlgorithmParams")
    @ApiOperation("批量修改算法参数")
    public ResponseResult batchUpdateAlgorithmParams(@RequestBody List<AlgorithmParams> algorithmParamsList) {
        boolean isOK = algorithmParamsService.batchUpdateAlgorithmParams(algorithmParamsList);
        if (isOK) {
            return ResponseResult.success();
        } else {
            return ResponseResult.error();
        }
    }

    @PostMapping("/deleteAlgorithmParams")
    @ApiOperation("删除算法参数")
    public ResponseResult deleteAlgorithmParams(String id) {
        boolean isOK = algorithmParamsService.deleteAlgorithmParams(id);
        if (isOK) {
            return ResponseResult.success();
        } else {
            return ResponseResult.error();
        }
    }

    @PostMapping("/callAlgorithmAnalyse")
    @ApiOperation("调用算法分析")
    public ResponseResult callAlgorithmAnalyse(String id,String componentId) {
        if (StrUtil.isBlank(id)|| StrUtil.isBlank(componentId)) {
            return ResponseResult.error("算法参数为空");
        }
        JSONObject data = algorithmParamsService.callAlgorithmAnalyse(id, componentId);
        return ResponseResult.successData(data);
    }
}
