package cd.casic.ci.api;


import cd.casic.ci.process.dto.req.template.TemplateCreateByDataReq;
import cd.casic.ci.process.dto.req.template.TemplateCreateReq;
import cd.casic.ci.process.dto.req.template.TemplateQueryReq;
import cd.casic.ci.process.dto.req.template.TemplateUpdateReq;
import cd.casic.ci.process.dto.resp.template.TemplateFindResp;
import cd.casic.ci.process.process.dataObject.base.BaseIdReq;
import cd.casic.ci.process.process.service.template.TemplateManagerService;
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 java.util.List;

/**
 * @ClassName PipelineController
 * @Author hopeli
 * @Date 2025/5/10 10:28
 * @Version 1.0
 */

@RestController
@RequestMapping("/template")
public class TemplateManagerController {

    @Resource
    private TemplateManagerService templateManagerService;

    @PostMapping(path="/createTemplate")
    public CommonResult<String> createTemplate(@RequestBody @Valid TemplateCreateReq req){
        String templateId = templateManagerService.createTemplateManager(req);
        return CommonResult.success(templateId);
    }



    @PostMapping(path="/createTemplateByData")
    public CommonResult<String> createTemplateByData(@RequestBody @Valid TemplateCreateByDataReq req){
        String templateId = templateManagerService.createTemplateByData(req);
        return CommonResult.success(templateId);
    }


    @PostMapping(path="/updateTemplateManager")
    public CommonResult<String> updateTemplateManager(@RequestBody TemplateUpdateReq req){
        String templateId = templateManagerService.updateTemplateManager(req);
        return CommonResult.success(templateId);
    }

    @PostMapping(path="/findTemplatePage")
    public CommonResult<PageResult<TemplateFindResp>> findTemplatePage(@RequestBody @NotNull @Valid TemplateQueryReq query){

        PageResult<TemplateFindResp> pipelineRespPage = templateManagerService.findTemplatePage(query);

        return CommonResult.success(pipelineRespPage);
    }

    @PostMapping(path="/findTemplateList")
    public CommonResult<List<TemplateFindResp>> findTemplateList(@RequestBody @Valid TemplateQueryReq query){

        List<TemplateFindResp> respList = templateManagerService.findTemplateList(query);

        return CommonResult.success(respList);
    }

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

        TemplateFindResp resp = templateManagerService.findTemplateById(req.getId());

        return CommonResult.success(resp);
    }
}
