package cd.casic.ci.api;


import cd.casic.ci.process.dto.req.testCase.TestCaseManagerQueryReq;
import cd.casic.ci.process.dto.req.testCase.TestCaseManagerReq;
import cd.casic.ci.process.dto.resp.sftpFile.FileBase64DownloadResp;
import cd.casic.ci.process.dto.resp.testCase.TestCaseManagerResp;
import cd.casic.ci.process.process.dataObject.base.BaseIdReq;
import cd.casic.ci.process.process.service.testCase.TestCaseManagerService;
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.*;

import java.util.List;

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

@RestController
@RequestMapping("/testCaseManager")
public class TestCaseManagerController {

    @Resource
    private TestCaseManagerService testCaseManagerService;

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

        String id = testCaseManagerService.create(req);

        return CommonResult.success(id);
    }


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

        testCaseManagerService.delete(req.getId());

        return CommonResult.success();
    }


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

        testCaseManagerService.updateTestCaseManager(req);

        return CommonResult.success();
    }


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

        List<TestCaseManagerResp> respList = testCaseManagerService.findList(query);

        return CommonResult.success(respList);
    }


    @PostMapping(path="/findPage")
    public CommonResult<PageResult<TestCaseManagerResp>> findPage(@RequestBody @NotNull @Valid TestCaseManagerQueryReq query){

        PageResult<TestCaseManagerResp> respPage = testCaseManagerService.findPage(query);
        return CommonResult.success(respPage);
    }


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

        TestCaseManagerResp resp = testCaseManagerService.findById(req.getId());

        return CommonResult.success(resp);
    }
    @GetMapping("/downLoadById")
    public CommonResult<FileBase64DownloadResp> downLoadByManagerId(@RequestParam String managerId){
        return CommonResult.success(testCaseManagerService.downLoadById(managerId));
    }
}
