package cd.casic.ci.api;

import cd.casic.ci.process.dto.req.shuimu.*;
import cd.casic.ci.process.dto.resp.shuimu.*;
import cd.casic.ci.process.process.service.shuimu.ShuiMuService;
import cd.casic.framework.commons.pojo.CommonResult;
import cd.casic.framework.commons.pojo.PageResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/shuimu")
public class ShuiMuController {
    @Resource
    private ShuiMuService shuiMuService;
    @GetMapping("/getToken")
    public CommonResult<String> getToken(){
        return CommonResult.success(shuiMuService.getToken().replace("Bearer ",""));
    }
    /**
     *  获取编译环境
     * */
    @GetMapping("/imageList")
    public CommonResult<List<String>> imageList(@RequestParam("label") String label){
        return CommonResult.success(shuiMuService.imageList(label));
    }
    @PostMapping("/createProject")
    public CommonResult<String> createProject(@RequestBody ShuiMuProjectCreateReq req){
        return CommonResult.success(shuiMuService.createProject(req));
    }
    /**
     *  获取检测配置
     * */
    @GetMapping("/readWfuzzJsonFile")
    public CommonResult<String> readWfuzzJsonFile(String projectId){
        return CommonResult.success(shuiMuService.readWfuzzJsonFile(projectId));
    }
    /**
     *  获取需要填写的表单项信息
     * */
    @GetMapping("/readHelpersJsonFile")
    public CommonResult<String> readHelpersJsonFile(String projectId){
        return CommonResult.success(shuiMuService.readHelpersJsonFile(projectId));
    }
    @GetMapping("/getProjectVersion")
    public CommonResult<ShuiMuProjectVersionResp> getProjectVersion(String projectId){
        return CommonResult.success(shuiMuService.getProjectVersion(projectId));
    }
    @GetMapping("/getProjectInfo")
    public CommonResult<ShuiMuProjectInfoResp> getProjectInfo(String projectId){
        return CommonResult.success(shuiMuService.getProjectInfo(projectId));
    }
    @PostMapping("/buildAndSaveConfig")
    public CommonResult<Void> buildAndSaveConfig(@RequestBody ShuiMuBuildAndSaveReq req){
        shuiMuService.buildAndSaveConfig(req);
        return CommonResult.success();
    }
    @PostMapping("/uploadWfuzzJson")
    public CommonResult<Void> uploadWfuzzJson(@RequestBody ShuiMuUpdateWFuzzJsonReq req){
        shuiMuService.uploadWfuzzJson(req);
        return CommonResult.success();
    }
    @PostMapping("/problemsOfTest")
    public CommonResult<PageResult<ShuiMuTestProblemResp>> problemsOfTest(@RequestBody ShuiMuTestProblemReq req){
        return CommonResult.success(shuiMuService.problemsOfTest(req));
    }
    @GetMapping("/getProjectReport")
    public CommonResult<ShuiMuProjectReportResp> getProjectReport(@RequestParam String projectId){
        return CommonResult.success(shuiMuService.getProjectReport(projectId));
    }
    @PostMapping("/createWebFuzzProject")
    public CommonResult<ShuiMuWebFuzzProjectCreateResp> createWebFuzzProject(@RequestBody ShuiMuWebFuzzProjectCreateUpdateReq req){
        return CommonResult.success(shuiMuService.createWebFuzzProject(req));
    }
    @GetMapping("/getWebFuzzProjectById")
    public CommonResult<ShuiMuWebFuzzProjectResp> getWebFuzzProjectById(@RequestParam String id){
        return CommonResult.success(shuiMuService.getWebFuzzProjectById(id));
    }
    @PostMapping("/createWebFuzzTest")
    public CommonResult<Void> createWebFuzzTest(@RequestParam String projectId){
        shuiMuService.createWebFuzzTest(projectId);
        return CommonResult.success();
    }
    @PostMapping("/updateWebFuzzProject")
    public CommonResult<Void> updateWebFuzzProject(ShuiMuWebFuzzProjectCreateUpdateReq req){
        shuiMuService.updateWebFuzzProject(req);
        return CommonResult.success();
    }
}
