package cd.casic.ci.api;


import cd.casic.ci.process.dto.req.task.TaskUpdateReq;
import cd.casic.ci.process.dto.req.template.TemplateTaskUpdateReq;
import cd.casic.ci.process.dto.resp.task.TasksResp;
import cd.casic.ci.process.dto.resp.template.TemplateTasksResp;
import cd.casic.ci.process.process.service.task.TaskService;
import cd.casic.ci.process.process.service.template.TemplateTaskService;
import cd.casic.framework.commons.pojo.CommonResult;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/templateTask")
public class TemplateTasksController {
    @Resource
    private TemplateTaskService taskService;
    /**
     * @pi.name:查询任务及任务详情
     * @pi.path:/tasks/findOneTasksOrTask
     * @pi.methodType:post
     * @pi.request-type: formdata
     * @pi.param: name=taskId;dataType=string;value=taskId;
     */
    @PostMapping(path="/findOneTasksOrTask/{taskId}")
    public CommonResult<TemplateTasksResp> findOneTasksOrTask(@NotNull @PathVariable String taskId){
        return CommonResult.success(taskService.getRespById(taskId));
    }
    /**
     *  复制task节点
     * */
    @PostMapping(path="/copyTask/{taskId}")
    public CommonResult<Void> copyTask(@NotEmpty @PathVariable String taskId){
        taskService.copyTask(taskId);
        return CommonResult.success();
    }
    @PostMapping(path="/updateTask")
    public CommonResult<Boolean> updateTask(@RequestBody TemplateTaskUpdateReq req){
        Boolean b = taskService.updateTask(req);
        return CommonResult.success(b);
    }

}
