package cn.iocoder.yudao.module.bpm.controller.admin.definition;

import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.filter.BpmInstallFilterRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.filter.BpmInstanceFilterPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.group.BpmUserGroupCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.group.BpmUserGroupPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.group.BpmUserGroupRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.group.BpmUserGroupUpdateReqVO;
import cn.iocoder.yudao.module.bpm.convert.definition.BpmInstallFilterConvert;
import cn.iocoder.yudao.module.bpm.convert.definition.BpmUserGroupConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmInstanceFilterDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmUserGroupDO;
import cn.iocoder.yudao.module.bpm.service.definition.BpmInstanceFilterService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmUserGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 流程实例过滤")
@RestController
@RequestMapping("/bpm/instance-filter")
@Validated
public class BpmInstanceFilterController {

    @Resource
    private BpmInstanceFilterService instanceFilterService;

    @PostMapping("/create")
    @Operation(summary = "添加需要过滤的流程实例")
    public CommonResult<Long> createInstanceFilter(@RequestParam("processInstanceId")String processInstanceId) {
        return success(instanceFilterService.createInstanceFilter(processInstanceId));
    }

    @PutMapping("/update")
    @Operation(summary = "更新流程实例是否需要过滤")
    public CommonResult<Boolean> updateInstanceFilterStatus(@RequestParam("id")Long id, @RequestParam("status") Integer status) {
        instanceFilterService.updateInstanceFilterStatus(id, status);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除过滤")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteUserGroup(@RequestParam("id") Long id) {
        instanceFilterService.deleteInstanceFilter(id);
        return success(true);
    }

    @GetMapping("/page")
    @Operation(summary = "获得流程实例过滤分页")
    public CommonResult<PageResult<BpmInstanceFilterDO>> getInstanceFilterPage(@Valid @ModelAttribute BpmInstanceFilterPageReqVO pageVO) {
        PageResult<BpmInstanceFilterDO> pageResult = instanceFilterService.getInstanceFilterPage(pageVO);
        return success(pageResult);
    }

}
