package com.uas.search.console.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.uas.search.console.schedule.model.TaskInformation;
import com.uas.search.console.schedule.service.TaskService;

@Controller
@RequestMapping("/schedule")
public class ScheduleController {

	@Autowired
	private TaskService taskService;

	@RequestMapping("/tasks")
	@ResponseBody
	public List<TaskInformation> allTaskInformations() {
		return taskService.allTaskInformations();
	}

	@RequestMapping("/start")
	@ResponseBody
	public String start() {
		return taskService.start();
	}

	@RequestMapping("/stop")
	@ResponseBody
	public String stop() {
		return taskService.stop();
	}

	@RequestMapping("/restart")
	@ResponseBody
	public String restart() {
		if (!taskService.isStopped()) {
			taskService.stop();
		}
		return taskService.start();
	}

	@RequestMapping("/isStopped")
	@ResponseBody
	public boolean isStopped() {
		return taskService.isStopped();
	}
}
