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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.copy.TaskCopyUserRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.copy.TaskCopyUserSaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.TaskCopyUserDO;
import cn.iocoder.yudao.module.bpm.service.definition.TaskCopyUserService;
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 static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * @Author: jinyd
 * @CreateTime: 2024/9/25  16:03
 * @Description:
 * @Version: 4.0
 */

@Tag(name = "管理后台 - 抄送用户")
@RestController
@RequestMapping("/bpm/task-copy-user")
@Validated
public class TaskCopyUserController {

    @Resource
    private TaskCopyUserService taskCopyUserService;

    @PostMapping("/create")
    @Operation(summary = "创建抄送用户")
    @PreAuthorize("@ss.hasPermission('bpm:task-copy-user:create')")
    public CommonResult<Long> createTaskCopyUser(@Valid @RequestBody TaskCopyUserSaveReqVO createReqVO) {
        return success(taskCopyUserService.createTaskCopyUser(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新抄送用户")
    @PreAuthorize("@ss.hasPermission('bpm:task-copy-user:update')")
    public CommonResult<Boolean> updateTaskCopyUser(@Valid @RequestBody TaskCopyUserSaveReqVO updateReqVO) {
        taskCopyUserService.updateTaskCopyUser(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除抄送用户")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('bpm:task-copy-user:delete')")
    public CommonResult<Boolean> deleteTaskCopyUser(@RequestParam("id") Long id) {
        taskCopyUserService.deleteTaskCopyUser(id);
        return success(true);
    }

    @GetMapping("/getByProcessDefinitionId")
    @Operation(summary = "根据流程定义主键获得抄送用户")
    @Parameter(name = "processDefinitionId", description = "流程定义主键", required = true, example = "nurse_change_1:8:03d7debe-7be9-11ef-b446-00155d6a6c52")
    public CommonResult<String> getByProcessDefinitionId(@RequestParam("processDefinitionId") String processDefinitionId) {
        return success(taskCopyUserService.getByProcessDefinitionId(processDefinitionId));
    }


}
