package cd.casic.ci.process.engine.scheduler.controller;

import cd.casic.ci.process.engine.scheduler.config.QuartzSchedulerManager;
import cd.casic.ci.process.engine.scheduler.req.PipelineSchedulingReq;
import cd.casic.framework.commons.pojo.CommonResult;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
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;

/**
 * @author HopeLi
 * @version v1.0
 * @ClassName PipelineTaskController
 * @Date: 2025/5/27 19:18
 * @Description:
 */


@RestController
@RequestMapping("/scheduler")
public class PipelineSchedulingController {

    @Resource
    private QuartzSchedulerManager quartzSchedulerManager;

    @PostMapping("/add")
    public CommonResult<Void> add(@RequestBody @Valid PipelineSchedulingReq req) throws Exception {
        quartzSchedulerManager.addTask(req);
        return CommonResult.success();
    }

    @PostMapping("/remove")
    public CommonResult<Void> remove(@RequestBody @Valid PipelineSchedulingReq req) throws Exception {
        quartzSchedulerManager.removeTask(req);
        return CommonResult.success();
    }

    @PostMapping("/update")
    public CommonResult<Void> update(@RequestBody @Valid PipelineSchedulingReq req) throws Exception {
        quartzSchedulerManager.updateTask(req);
        return CommonResult.success();
    }

    @PostMapping("/start")
    public CommonResult<Void> start(@RequestBody @Valid PipelineSchedulingReq req) throws Exception {
        quartzSchedulerManager.startTask(req);
        return CommonResult.success();
    }
}
