package com.ruoyi.sim.controller;

import java.util.List;

import com.ruoyi.sim.domain.Task;
import com.ruoyi.sim.domain.vo.TaskCUVo;
import com.ruoyi.sim.domain.vo.TaskVo;
import com.ruoyi.sim.service.impl.TaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务Controller
 *
 * @author tom
 * @date 2024-12-13
 */
@RestController
@RequestMapping("/sim/task")
@Api("任务Controller")
public class TaskController extends BaseController {

    protected final Logger l = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private TaskService taskService;

    @GetMapping("/list")
    @ApiOperation("查询任务列表")
    public TableDataInfo list(Task q) {
        startPage();
        List<TaskVo> list = taskService.list(q);
        return getDataTable(list);
    }

    @GetMapping(value = "/{taskId}")
    @ApiOperation("获取任务详细信息")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId) {
        return taskService.selectTaskByTaskId(taskId);
    }

    @PostMapping(path = "/obj")
    @ApiOperation("新增任务Obj")
    public AjaxResult addObj(@RequestBody TaskVo tv) {
        return taskService.insertTaskByTeacher(tv);
    }

    @PostMapping(path = "/")
    @ApiOperation("新增任务")
    public AjaxResult add(@RequestBody TaskCUVo vo) {
        if (vo != null) {
            vo.setTaskId(null);
        }
        return taskService.insertOrUpdateTaskByTeacher(vo);
    }

    @PutMapping(path = "/obj")
    @ApiOperation("修改任务Obj")
    public AjaxResult editObj(@RequestBody TaskVo tv) {
        return taskService.updateTaskByTeacher(tv);
    }

    @PutMapping(path = "/")
    @ApiOperation("修改任务")
    public AjaxResult edit(@RequestBody TaskCUVo vo) {
        return taskService.insertOrUpdateTaskByTeacher(vo);
    }

    @DeleteMapping("/{taskIds}")
    @ApiOperation("批量删除任务")
    public AjaxResult remove(@PathVariable Long[] taskIds) {
        return taskService.deleteTaskByTaskIds(taskIds);
    }

    // -------------------------------- tom add  --------------------------------


    @GetMapping("/getInfoForAdd/{simType}")
    @ApiOperation("为了新建Task，返回一个带tree结构的任务详细信息。")
    public AjaxResult getInfoForAdd(@PathVariable("simType") String simType) {
        return taskService.getInfoForAdd(simType);
    }
}
