package org.eco.als.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.StrUtil;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.eco.als.domain.bo.AlgorithmBo;
import org.eco.als.domain.bo.QaBo;
import org.eco.als.domain.bo.TaskBo;
import org.eco.als.service.IAlgorithmService;
import org.eco.common.core.core.domain.CommonResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 算法相关控制
 *
 * @Author: GaoKun Wang
 * @Date: 2024/7/30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/als/algorithm")
public class AlgorithmController {
    @Resource
    private IAlgorithmService algorithmService;

    /**
     * 执行预处理
     *
     * @param algorithmBo 入参
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @SaCheckPermission("als:algorithm:execute")
    @PostMapping("/execute/pro")
    public CommonResult<String> executePro(@Validated @RequestBody AlgorithmBo algorithmBo) {
        String result = algorithmService.executePro(algorithmBo);
        return StrUtil.isBlank(result) ? CommonResult.fail() : CommonResult.success(result, "");
    }

    /**
     * 执行虚警抑制
     *
     * @param algorithmBo 入参
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @PostMapping("/execute/falseAlarm")
    public CommonResult<String> executeFalseAlarm(@Validated @RequestBody AlgorithmBo algorithmBo) {
        String result = algorithmService.executeFalseAlarm(algorithmBo);
        return StrUtil.isBlank(result) ? CommonResult.fail() : CommonResult.success(result, "");
    }

    /**
     * 执行故障诊断
     *
     * @param algorithmBo 入参
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @PostMapping("/execute/fault")
    public CommonResult<String> executeFault(@Validated @RequestBody AlgorithmBo algorithmBo) {
        String result = algorithmService.executeFault(algorithmBo);
        return StrUtil.isBlank(result) ? CommonResult.fail() : CommonResult.success(result, "");
    }

    /**
     * 退化评估
     *
     * @param algorithmBo 入参
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @PostMapping("/execute/evaluation")
    public CommonResult<String> executeEvaluation(@Validated @RequestBody AlgorithmBo algorithmBo) {
        String result = algorithmService.executeEvaluation(algorithmBo);
        return StrUtil.isBlank(result) ? CommonResult.fail() : CommonResult.success(result, "");
    }

    /**
     * 执行任务管理
     *
     * @param taskBo 入参
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @SaCheckPermission("als:algorithm:execute")
    @PostMapping("/execute/task")
    public CommonResult<String> batchExecute(@Validated @RequestBody TaskBo taskBo) {
        String result = algorithmService.batchExecute(taskBo);
        return StrUtil.isBlank(result) ? CommonResult.fail() : CommonResult.success(result, "");
    }

    /**
     * 获取数据参数名称
     *
     * @param ossId 入参数据
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @GetMapping("/{ossId}")
    public CommonResult<List<String>> getDataHeader(@PathVariable Long ossId) {
        return CommonResult.success(algorithmService.getDataHeader(ossId));
    }

    /**
     * 获取数据根据OssId
     *
     * @param ossId 入参数据
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @GetMapping("/data/{ossId}")
    public CommonResult<String> getDataByOssId(@PathVariable Long ossId) {
        return CommonResult.success(algorithmService.getDataByOssId(ossId), "");
    }

    /**
     * 获取曲线数据根据OssId
     *
     * @param ossId 入参数据
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @GetMapping("/playback/data/{ossId}")
    public CommonResult<String> getPlaybackDataByOssId(@PathVariable Long ossId) {
        return CommonResult.success(algorithmService.getDataByOssId(ossId), "");
    }

    /**
     * 问答
     *
     * @param QaBo 入参
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @PostMapping("/execute/qa")
    public CommonResult<String> executeQa(@Validated @RequestBody QaBo QaBo) {
        return CommonResult.success(algorithmService.executeQa(QaBo), "");
    }
}
