package com.jwipc.sys.controller.pc;

import com.jwipc.sys.dto.JobAddDTO;
import com.jwipc.sys.logic.JobLogic;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.jwipc.sys.constant.ModuleConst.MODULE_ROOT;

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@RestController
@RequestMapping(MODULE_ROOT + "/job")
public class JobManagerRestController {
    @Resource
    private JobLogic jobLogic;

    @GetMapping("list")
    public ResponseEntity list() {
        return ResponseEntity.ok(jobLogic.list());
    }

    @GetMapping("get")
    public ResponseEntity get(String jobName) {
        return ResponseEntity.ok(jobLogic.get(jobName));
    }

    @PostMapping("save")
    public ResponseEntity save(JobAddDTO jobName) {
        return jobLogic.add(jobName);
    }

    @PostMapping("update")
    public ResponseEntity update(JobAddDTO jobName) {
        return jobLogic.update(jobName);
    }

    @PostMapping("run")
    public ResponseEntity run(String jobName) {
        return jobLogic.run(jobName);
    }

    @PostMapping("stop")
    public ResponseEntity stop(String jobName) {
        return jobLogic.stop(jobName);
    }

    @PostMapping("pause")
    public ResponseEntity pause(String jobName) {
        return jobLogic.pause(jobName);
    }


    @PostMapping("resume")
    public ResponseEntity resume(String jobName) {
        return jobLogic.resume(jobName);
    }

    @PostMapping("remove")
    public ResponseEntity remove(String jobName) {
        return jobLogic.remove(jobName);
    }


}
