package com.css.simulation.resource.server.adapter.controller.algorithm_library;


import api.common.pojo.common.ResponseBodyVO;
import api.common.pojo.constants.LogConstants;
import api.common.pojo.param.algorithm.AlgorithmParameter;
import com.css.simulation.resource.server.app.service.AlgorithmService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 算法库模块
 */
@RestController
@RequestMapping(value = "/algorithm", name = LogConstants.MODULE_ALGORITH)
public class AlgorithmLibraryController {

    @Resource
    private AlgorithmService algorithmService;

    //* -------------------------------- Comm删除算法ent --------------------------------
    @RequestMapping("deleteByid")
    public ResponseBodyVO<String> deleteById(@RequestBody AlgorithmParameter param) {
        return algorithmService.deleteById(param);
    }
    //* -------------------------------- Comment --------------------------------


    /**
     * 新增/修改算法
     */
    @RequestMapping("addOrUpdate")
    public ResponseBodyVO<Object> addOrUpdate(@RequestBody AlgorithmParameter param) {
        return algorithmService.addOrUpdate(param);
    }


    /**
     * 查询算法列表-私有导入和私有仓库页面
     */
    @RequestMapping("selectAlgorithmList")
    public ResponseBodyVO<Object> selectAlgorithmList(@RequestBody AlgorithmParameter param) {
        return algorithmService.selectAlgorithmList(param);
    }

    /**
     * 查询算法列表-算法平台页面
     */
    @RequestMapping("selectAlgoPlatformList")
    public ResponseBodyVO<Object> selectAlgoPlatformList(@RequestBody AlgorithmParameter param) {
        return algorithmService.selectAlgoPlatformList(param);
    }


    /**
     * 查询算法列表-公有页面
     */
    @RequestMapping("selectSharedAlgorithmList")
    public ResponseBodyVO<Object> selectSharedAlgorithmList(@RequestBody AlgorithmParameter param) {
        return algorithmService.selectSharedAlgorithmList(param);
    }


    /**
     * 删除算法前校验
     */
    @RequestMapping("deleteCheck")
    public ResponseBodyVO<Map<String, String>> deleteCheck(@RequestBody AlgorithmParameter param) {
        return algorithmService.deleteCheck(param);
    }


    /**
     * 分享算法
     */
    @RequestMapping("shareAlgorithm")
    public ResponseBodyVO<Object> shareAlgorithm(@RequestBody AlgorithmParameter param) {
        return algorithmService.shareAlgorithm(param);
    }


    /**
     * 查看算法详情
     */
    @RequestMapping("selectDetailsById")
    public ResponseBodyVO<Object> selectDetailsById(@RequestBody AlgorithmParameter param) {
        String algorithmId = param.getId();
        return algorithmService.selectDetailsById(algorithmId);
    }

    /**
     * git测试连接
     */
    @RequestMapping("testConnection")
    public ResponseBodyVO<String> testConnection(@RequestBody AlgorithmParameter param) {
        return algorithmService.testConnection(param);
    }

    /**
     * 根据git仓库地址获取版本号
     */
    @RequestMapping("getGitVersion")
    public ResponseBodyVO<String> getGitVersion(@RequestBody AlgorithmParameter param) {
        String id = param.getId();
        String gitVersion = algorithmService.getGitVersion(id);
        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, "请求成功。", gitVersion);
    }

}
