package com.dayou.controller;

import com.dayou.vo.NameCodeVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.service.workflow.IWorkNodeTaskService;
import com.dayou.entity.WorkNodeTask;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工作流节点任务
 *
 * @author wucl
 * @since 2023-10-17
 */
@RestController
@RequestMapping("workNodeTask")
@Slf4j
public class WorkNodeTaskController extends BaseController {
    @Autowired
    private IWorkNodeTaskService workNodeTaskService;

    /**
    * 工作流节点任务列表
    */
    @GetMapping("")
    public RestResponse<Page<WorkNodeTask>> page(WorkNodeTask workNodeTask, Page page){
        Page<WorkNodeTask> pages=workNodeTaskService.selectPage(page,workNodeTask);
        return RestResponse.data(pages);
    }

    /**
     * 工作流节点任务详情
     */
    @GetMapping("/{id}")
    public RestResponse<WorkNodeTask> detail(@PathVariable Long id){
        WorkNodeTask xWorkNodeTask =workNodeTaskService.detail(id);
        return RestResponse.data(xWorkNodeTask);
     }

    /**
     * 工作流节点任务新增
     */
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody WorkNodeTask workNodeTask) {
        Boolean ret = workNodeTaskService.add(workNodeTask);
        return RestResponse.data(ret);
    }

    /**
     * 工作流节点任务更新
     */
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody WorkNodeTask workNodeTask) {
        Boolean ret = workNodeTaskService.update(workNodeTask);
        return RestResponse.data(ret);
    }

    /**
     * 工作流节点任务删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = workNodeTaskService.delete(id);
        return RestResponse.data(ret);
    }

    /**
     * 节点任务枚举
     * @return
     */
    @GetMapping("/enum")
    public RestResponse<List<WorkNodeTask>> allNodeTask(){
        List<WorkNodeTask> enums = workNodeTaskService.allNodeTask();
        return RestResponse.data(enums);
    }

    /**
     * 节点任务枚举
     * @return
     */
    @GetMapping("/permission/enum")
    public RestResponse<List<NameCodeVO>> allHandlerPermission(){
        List<NameCodeVO> enums = workNodeTaskService.allHandlerPermission();
        return RestResponse.data(enums);
    }
}

