package org.wcs.serve.controller.app;


import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.wcs.model.dto.serve.quartz.AddQuartzConfigReq;
import org.wcs.model.dto.serve.quartz.QuartzReq;
import org.wcs.model.dto.serve.quartz.UpdateQuartzConfigReq;
import org.wcs.model.vo.serve.AppServeDataResponse;
import org.wcs.model.vo.serve.AppServeResponse;
import org.wcs.model.vo.serve.quartz.QueryResp;
import org.wcs.serve.service.intf.IQuartzService;

import java.util.List;

/**
 * 定时任务相关操作
 */
@RestController
@RequestMapping("/app/quartz")
@ResponseBody
@RequiredArgsConstructor
public class QuartzController {

    private final IQuartzService quartzService;

    /**
     * 查询定时任务列表
     * @param quartzReq 查询参数
     * @return 结果
     */
    @PostMapping("/query")
    public AppServeDataResponse<List<QueryResp>> query(@RequestBody QuartzReq quartzReq) {
        return quartzService.query(quartzReq);
    }

    /**
     * 添加一条定时任务数据
     * @param addQuartzConfigReq 定时任务数据
     * @return 添加结果
     */
    @PostMapping("/addQuartzConfig")
    public AppServeResponse addQuartzConfig(@RequestBody @Validated AddQuartzConfigReq addQuartzConfigReq) {
        return quartzService.addQuartzConfig(addQuartzConfigReq);
    }

    /**
     * 删除一条定时任务数据
     * @param className 类名
     * @return 结果
     */
    @DeleteMapping("/deleteQuartzConfig/{className}")
    public AppServeResponse deleteQuartzConfig(@PathVariable @NotBlank(message = "类名不能为空") String className) {
        return quartzService.deleteQuartzConfig(className);
    }

    /**
     * 停止一条定时任务
     * @param className 类名
     * @return 结果
     */
    @PutMapping("/stopQuartzJob/{className}")
    public AppServeResponse stopQuartzJob(@PathVariable @NotBlank(message = "任务名称不能为空") String className) {
        return quartzService.stopQuartzJob(className);
    }

    /**
     * 启动一条定时任务
     * @param className 类名
     * @return 启动结果
     */
    @PutMapping("/startQuartzJob/{className}")
    public AppServeResponse startQuartzJob(@PathVariable @NotBlank(message = "任务名称不能为空") String className) {
        return quartzService.startQuartzJob(className);
    }

    /**
     * 更新一条定时任务数据
     * @param updateQuartzConfigReq 定时任务数据
     * @return 更新结果
     */
    @PostMapping("/updateQuartzConfig")
    public AppServeResponse updateQuartzConfig(@RequestBody @Validated UpdateQuartzConfigReq updateQuartzConfigReq) {
        return quartzService.updateQuartzConfig(updateQuartzConfigReq);
    }


}
