/*
 * Copyright (c) 2023 codvision.com All Rights Reserved.
 */

package com.codvision.workflow.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codvision.commoncore.common.ResponseEntity;
import com.codvision.commoncore.exception.BusinessException;
import com.codvision.webcore.bean.QueryPage;
import com.codvision.workflow.entity.WorkFlowListener;
import com.codvision.workflow.service.WorkFlowListenerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author hxl
 */
@Slf4j
@Api(tags = "工作流监听器管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/flowListener")
public class WorkFlowListenerController {

    private final WorkFlowListenerService service;

    @PostMapping("/getPageResult")
    @ApiOperation("分页列表")
    public ResponseEntity<IPage<WorkFlowListener>> getPageResult(@RequestBody QueryPage<Map<String, Object>> queryPage) {
        return new ResponseEntity<IPage<WorkFlowListener>>().data(service.getPageResult(queryPage));
    }

    @PostMapping("/update")
    @ApiOperation("更新")
    public ResponseEntity<String> update(@RequestBody WorkFlowListener workFlowListener) {
        ResponseEntity<String> responseEntity = new ResponseEntity<>();
        if (workFlowListener.getId() == null) {
           throw new BusinessException(30002);
        }

        service.updateById(workFlowListener);
        return responseEntity.ok();
    }

    @PostMapping("/del")
    @ApiOperation("删除")
    public ResponseEntity<String> del(@RequestParam(value = "id") Integer id) {
        ResponseEntity<String> responseEntity = new ResponseEntity<>();
        if (id == null) {
            throw new BusinessException(30002);
        }

        service.removeById(id);
        return responseEntity.ok();
    }

}
