package com.css.simulation.resource.scheduler.adapter.controller;


import api.common.pojo.param.project.MultiSimulationProjectKafkaParam;
import com.css.simulation.resource.scheduler.app.service.ProjectApplicationService;
import com.css.simulation.resource.scheduler.app.service.TaskApplicationService;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RefreshScope
@RestController
@RequestMapping("/task")
public class TaskController {

    @Resource
    private TaskApplicationService taskApplicationService;
    @Resource
    private ProjectApplicationService projectApplicationService;
    //* -------------------------------- Comment --------------------------------

    /**
     * 任务执行前调用该接口，确定该任务没有被终止
     */
    @GetMapping("/confirm")
    public Boolean confirm(@RequestParam("taskId") String taskId) {
        return taskApplicationService.confirm(taskId);
    }

    // -------------------------------- Comment --------------------------------

    /**
     * Pod 的心跳接口
     */
    @GetMapping("/tick")
    public void tick(@RequestParam("taskId") String taskId) {
        taskApplicationService.tick(taskId);
    }
    //* -------------------------------- Comment --------------------------------

    /**
     * 修改任务状态
     */
    @GetMapping("/state")
    public void state(@RequestParam("taskId") String taskId, @RequestParam("state") String state, @RequestParam("podName") String podName) {
        taskApplicationService.state(taskId, state, podName);
    }

    @GetMapping("/multiState")
    public void multiState(@RequestParam("taskId") String taskId, @RequestParam("state") String state, @RequestParam("podName") String podName) {
        taskApplicationService.multiState(taskId, state, podName);
    }

    @PostMapping(path = "/runMultiProject", produces = "application/json;charset=utf-8")
    public void runMultiProject(@RequestBody MultiSimulationProjectKafkaParam param) {
        projectApplicationService.runMultiProject(param);
    }

    @PostMapping(path = "/stopMultiProject", produces = "application/json;charset=utf-8")
    public void stopMultiProject(@RequestBody MultiSimulationProjectKafkaParam param) {
        projectApplicationService.stopMultiProject(param);
    }

    @GetMapping("/multiConfirm")
    public Boolean multiConfirm(@RequestParam("taskId") String taskId) {
        return taskApplicationService.multiConfirm(taskId);
    }

    @GetMapping("/multiTick")
    public void multiTick(@RequestParam("taskId") String taskId) {
        taskApplicationService.multiTick(taskId);
    }


}
