package cd.casic.ci.api;


import cd.casic.ci.process.dto.req.testCase.TestCaseInfoQueryReq;
import cd.casic.ci.process.dto.req.testCase.TestCaseInfoReq;
import cd.casic.ci.process.dto.resp.testCase.TestCaseInfoResp;
import cd.casic.ci.process.process.dataObject.base.BaseIdReq;
import cd.casic.ci.process.process.service.testCase.TestCaseInfoService;
import cd.casic.framework.commons.pojo.CommonResult;
import cd.casic.framework.commons.pojo.PageResult;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @ClassName ResourceController
 * @Author hopeli
 * @Date 2025/5/10 10:57
 * @Version 1.0
 */

@RestController
@RequestMapping("/testCase")
public class TestCaseInfoController {

    @Resource
    private TestCaseInfoService testCaseInfoService;

    @PostMapping(path="/create")
    public CommonResult<String> create(@RequestBody @Valid TestCaseInfoReq req){

        String id = testCaseInfoService.create(req);

        return CommonResult.success(id);
    }


    @PostMapping(path="/delete")
    public CommonResult<Void> delete(@RequestBody @Valid BaseIdReq req){

        testCaseInfoService.delete(req.getId());

        return CommonResult.success();
    }


    @PostMapping(path="/update")
    public CommonResult<Void> update(@RequestBody @NotNull @Valid TestCaseInfoReq req){

        testCaseInfoService.updateTestCaseInfo(req);

        return CommonResult.success();
    }


    @PostMapping(path="/findList")
    public CommonResult<List<TestCaseInfoResp>> findList(@RequestBody @Valid TestCaseInfoQueryReq query){

        List<TestCaseInfoResp> respList = testCaseInfoService.findList(query);

        return CommonResult.success(respList);
    }


    @PostMapping(path="/findPage")
    public CommonResult<PageResult<TestCaseInfoResp>> findResourcePage(@RequestBody @NotNull @Valid TestCaseInfoQueryReq query){

        PageResult<TestCaseInfoResp> respPage = testCaseInfoService.findPage(query);
        return CommonResult.success(respPage);
    }


    @PostMapping(path="/findById")
    public CommonResult<TestCaseInfoResp> findById(@RequestBody @Valid BaseIdReq req){

        TestCaseInfoResp resp = testCaseInfoService.findById(req.getId());

        return CommonResult.success(resp);
    }


    @PostMapping(path="/findFileTypeList")
    public CommonResult<List<String>> findFileTypeList(){

        List<String> respList = testCaseInfoService.findFileTypeList();

        return CommonResult.success(respList);
    }

    @PostMapping("/checkTestCaseExist")
    public CommonResult<String>  checkTestCaseExist(MultipartFile file){
        String s = testCaseInfoService.checkTestCaseExist(file);
        return CommonResult.success(s);
    }
}
