package com.mosquito.project.permission;

import com.mosquito.project.dto.ApiResponse;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 审批流程控制器
 *
 * 业务回调统一在 ApprovalFlowService.handleApproval() -> processAfterApproval() 中处理
 * Controller 仅负责接收请求、权限校验、调用Service
 */
@RestController
@RequestMapping("/api/v1/approval")
public class ApprovalController {

    private static final Logger log = LoggerFactory.getLogger(ApprovalController.class);

    private final ApprovalFlowService approvalFlowService;
    private PermissionCheckService permissionCheckService;

    public ApprovalController(ApprovalFlowService approvalFlowService) {
        this.approvalFlowService = approvalFlowService;
    }

    /**
     * 设置PermissionCheckService（用于handle接口权限校验）
     */
    @Autowired(required = false)
    public void setPermissionCheckService(PermissionCheckService permissionCheckService) {
        this.permissionCheckService = permissionCheckService;
    }

    /**
     * 获取审批流列表
     */
    @GetMapping("/flows")
    @RequirePermission("approval.index.view.ALL")
    public ApiResponse<List<SysApprovalFlow>> getFlows() {
        return ApiResponse.success(approvalFlowService.getAllFlows());
    }

    /**
     * 获取启用的审批流
     */
    @GetMapping("/flows/enabled")
    @RequirePermission("approval.index.view.ALL")
    public ApiResponse<List<SysApprovalFlow>> getEnabledFlows() {
        return ApiResponse.success(approvalFlowService.getEnabledFlows());
    }

    /**
     * 获取单个审批流详情
     */
    @GetMapping("/flows/{id}")
    @RequirePermission("approval.index.view.ALL")
    public ApiResponse<SysApprovalFlow> getFlowById(@PathVariable Long id) {
        return ApiResponse.success(approvalFlowService.getFlowById(id));
    }

    /**
     * 创建审批流程配置
     */
    @PostMapping("/flows")
    @RequirePermission("approval.flow.manage.ALL")
    public ApiResponse<SysApprovalFlow> createFlow(@RequestBody Map<String, Object> request) {
        try {
            SysApprovalFlow flow = approvalFlowService.createFlow(request);
            return ApiResponse.success(flow, "审批流程创建成功");
        } catch (Exception e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 更新审批流程配置
     */
    @PutMapping("/flows/{id}")
    @RequirePermission("approval.flow.manage.ALL")
    public ApiResponse<SysApprovalFlow> updateFlow(
            @PathVariable Long id,
            @RequestBody Map<String, Object> request) {
        try {
            SysApprovalFlow flow = approvalFlowService.updateFlow(id, request);
            return ApiResponse.success(flow, "审批流程更新成功");
        } catch (Exception e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 删除审批流程配置
     */
    @DeleteMapping("/flows/{id}")
    @RequirePermission("approval.flow.manage.ALL")
    public ApiResponse<Void> deleteFlow(@PathVariable Long id) {
        try {
            approvalFlowService.deleteFlow(id);
            return ApiResponse.success(null, "审批流程删除成功");
        } catch (Exception e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 启用/禁用审批流程
     */
    @PostMapping("/flows/{id}/toggle")
    @RequirePermission("approval.flow.manage.ALL")
    public ApiResponse<SysApprovalFlow> toggleFlowStatus(
            @PathVariable Long id,
            @RequestBody Map<String, Boolean> request) {
        try {
            Boolean enabled = request.getOrDefault("enabled", true);
            SysApprovalFlow flow = approvalFlowService.toggleFlowStatus(id, enabled);
            return ApiResponse.success(flow, enabled ? "审批流程已启用" : "审批流程已禁用");
        } catch (Exception e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 提交审批申请 - 只信任登录态用户
     */
    @PostMapping("/submit")
    @RequirePermission("approval.index.submit.ALL")
    public ApiResponse<Map<String, Object>> submitApproval(
            @RequestBody ApprovalSubmitRequest request,
            HttpServletRequest httpRequest) {
        try {
            // 只信任登录态用户，忽略请求体中的applicantId
            Long currentUserId = getCurrentUserId(httpRequest);
            if (currentUserId == null) {
                return ApiResponse.error(401, "未获取到用户信息");
            }

            Map<String, Object> result = approvalFlowService.submitApproval(
                    request.getFlowId(),
                    request.getBizType(),
                    request.getBizId(),
                    request.getTitle(),
                    currentUserId, // 使用登录用户ID，忽略请求中的applicantId
                    request.getApplyReason()
            );
            return ApiResponse.success(result, "审批提交成功");
        } catch (IllegalArgumentException e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 通过触发事件提交审批 - 只信任登录态用户
     */
    @PostMapping("/submit-by-event")
    @RequirePermission("approval.index.submit.ALL")
    public ApiResponse<Map<String, Object>> submitApprovalByEvent(
            @RequestBody ApprovalSubmitByEventRequest request,
            HttpServletRequest httpRequest) {
        try {
            // 只信任登录态用户，忽略请求体中的applicantId
            Long currentUserId = getCurrentUserId(httpRequest);
            if (currentUserId == null) {
                return ApiResponse.error(401, "未获取到用户信息");
            }

            Map<String, Object> result = approvalFlowService.submitApprovalByEvent(
                    request.getTriggerEvent(),
                    request.getBizType(),
                    request.getBizId(),
                    request.getTitle(),
                    currentUserId, // 使用登录用户ID
                    request.getApplyReason()
            );
            return ApiResponse.success(result, "审批提交成功");
        } catch (IllegalArgumentException e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 获取待审批列表 - 只信任登录态用户
     */
    @GetMapping("/pending")
    @RequirePermission("approval.index.view.ALL")
    public ApiResponse<List<SysApprovalRecord>> getPendingApprovals(HttpServletRequest request) {
        Long currentUserId = getCurrentUserId(request);
        if (currentUserId == null) {
            return ApiResponse.error(401, "未获取到用户信息");
        }
        return ApiResponse.success(approvalFlowService.getPendingApprovals(currentUserId));
    }

    /**
     * 检查当前用户是否有已批准的敏感导出审批
     */
    @GetMapping("/has-export-approval")
    @RequirePermission("user.index.export.ALL")
    public ApiResponse<Boolean> hasExportApproval(HttpServletRequest request) {
        Long currentUserId = getCurrentUserId(request);
        if (currentUserId == null) {
            return ApiResponse.error(401, "未获取到用户信息");
        }
        boolean hasApproved = approvalFlowService.hasApprovedExport(currentUserId);
        return ApiResponse.success(hasApproved);
    }

    /**
     * 获取已审批列表 - 只信任登录态用户
     */
    @GetMapping("/processed")
    @RequirePermission("approval.index.view.ALL")
    public ApiResponse<List<SysApprovalRecord>> getProcessedList(HttpServletRequest request) {
        Long currentUserId = getCurrentUserId(request);
        if (currentUserId == null) {
            return ApiResponse.error(401, "未获取到用户信息");
        }
        return ApiResponse.success(approvalFlowService.getApprovedList(currentUserId));
    }

    /**
     * 获取我发起的审批 - 只信任登录态用户
     */
    @GetMapping("/my")
    @RequirePermission("approval.index.view.ALL")
    public ApiResponse<List<SysApprovalRecord>> getMyApplications(HttpServletRequest request) {
        Long currentUserId = getCurrentUserId(request);
        if (currentUserId == null) {
            return ApiResponse.error(401, "未获取到用户信息");
        }
        return ApiResponse.success(approvalFlowService.getMyApplications(currentUserId));
    }

    /**
     * 批量处理审批 - 只信任登录态用户
     * 支持批量通过/拒绝/转交，返回成功/失败明细
     */
    @PostMapping("/batch-handle")
    @RequirePermission("approval.index.batch.handle.ALL")
    public ApiResponse<Map<String, Object>> batchHandleApproval(
            @RequestBody ApprovalBatchHandleRequest request,
            HttpServletRequest httpRequest) {
        try {
            Long currentUserId = getCurrentUserId(httpRequest);
            if (currentUserId == null) {
                return ApiResponse.error(401, "未获取到用户信息");
            }

            if (request.getRecordIds() == null || request.getRecordIds().isEmpty()) {
                return ApiResponse.error(400, "请选择要处理的审批记录");
            }

            // 批量转交操作需要额外校验批量转交权限
            if ("TRANSFER".equalsIgnoreCase(request.getAction())) {
                if (permissionCheckService != null && !permissionCheckService.hasPermission(currentUserId, "approval.index.batch.transfer.ALL")) {
                    log.warn("用户尝试执行批量转交但无权限: userId={}", currentUserId);
                    return ApiResponse.error(403, "无批量转交权限");
                }
            }

            Map<String, Object> result = approvalFlowService.batchHandleApproval(
                    request.getRecordIds(),
                    request.getAction(),
                    currentUserId,
                    request.getComment()
            );

            // 审批通过后的业务回调已在 batchHandleApproval -> handleApproval 中统一处理

            return ApiResponse.success(result, "批量处理完成");
        } catch (Exception e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 审批通过 - 只信任登录态用户
     * 审批通过后根据业务类型执行相应的回调逻辑
     */
    @PostMapping("/approve")
    @RequirePermission("approval.execute.approve.ALL")
    public ApiResponse<Map<String, Object>> approve(
            @RequestBody ApprovalHandleRequest request,
            HttpServletRequest httpRequest) {
        try {
            // 只信任登录态用户，忽略请求体中的operatorId
            Long currentUserId = getCurrentUserId(httpRequest);
            if (currentUserId == null) {
                return ApiResponse.error(401, "未获取到用户信息");
            }

            Map<String, Object> result = approvalFlowService.handleApproval(
                    request.getRecordId(),
                    "APPROVE",
                    currentUserId, // 使用登录用户ID
                    request.getComment()
            );

            // 审批通过后的业务回调已在 ApprovalFlowService.handleApproval() 中统一处理

            return ApiResponse.success(result, "审批通过成功");
        } catch (IllegalArgumentException e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 审批拒绝 - 只信任登录态用户
     */
    @PostMapping("/reject")
    @RequirePermission("approval.execute.reject.ALL")
    public ApiResponse<Map<String, Object>> reject(
            @RequestBody ApprovalHandleRequest request,
            HttpServletRequest httpRequest) {
        try {
            // 只信任登录态用户，忽略请求体中的operatorId
            Long currentUserId = getCurrentUserId(httpRequest);
            if (currentUserId == null) {
                return ApiResponse.error(401, "未获取到用户信息");
            }

            Map<String, Object> result = approvalFlowService.handleApproval(
                    request.getRecordId(),
                    "REJECT",
                    currentUserId, // 使用登录用户ID
                    request.getComment()
            );

            return ApiResponse.success(result, "审批拒绝成功");
        } catch (IllegalArgumentException e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 审批转交 - 只信任登录态用户
     */
    @PostMapping("/transfer")
    @RequirePermission("approval.execute.transfer.ALL")
    public ApiResponse<Map<String, Object>> transfer(
            @RequestBody ApprovalHandleRequest request,
            HttpServletRequest httpRequest) {
        try {
            // 只信任登录态用户，忽略请求体中的operatorId
            Long currentUserId = getCurrentUserId(httpRequest);
            if (currentUserId == null) {
                return ApiResponse.error(401, "未获取到用户信息");
            }

            if (request.getTransferTo() == null) {
                return ApiResponse.error(400, "转交目标用户不能为空");
            }

            // 使用transferTo字段构造comment
            String comment = "transfer:" + request.getTransferTo();
            if (request.getComment() != null && !request.getComment().isBlank()) {
                comment = request.getComment() + " -> " + comment;
            }

            Map<String, Object> result = approvalFlowService.handleApproval(
                    request.getRecordId(),
                    "TRANSFER",
                    currentUserId, // 使用登录用户ID
                    comment
            );

            return ApiResponse.success(result, "审批转交成功");
        } catch (IllegalArgumentException e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 处理审批（兼容旧版）- 只信任登录态用户
     * 审批通过后的业务回调已在 ApprovalFlowService.handleApproval() -> processAfterApproval() 中统一处理
     * @deprecated 请使用 /approve, /reject, /transfer 三个独立接口
     * 注意：此接口仍然检查action对应的execute权限，防止权限绕过
     */
    @PostMapping("/handle")
    @RequirePermission("approval.index.handle.ALL")
    public ApiResponse<Map<String, Object>> handleApproval(
            @RequestBody ApprovalHandleRequest request,
            HttpServletRequest httpRequest) {
        try {
            // 只信任登录态用户，忽略请求体中的operatorId
            Long currentUserId = getCurrentUserId(httpRequest);
            if (currentUserId == null) {
                return ApiResponse.error(401, "未获取到用户信息");
            }

            // 根据action二次校验execute权限，防止权限绕过
            if (permissionCheckService != null) {
                String requiredPermission = getExecutePermissionForAction(request.getAction());
                if (requiredPermission != null && !permissionCheckService.hasPermission(currentUserId, requiredPermission)) {
                    log.warn("用户尝试通过/handle接口绕过execute权限: userId={}, action={}, requiredPermission={}",
                            currentUserId, request.getAction(), requiredPermission);
                    return ApiResponse.error(403, "无权限执行此操作");
                }
            }

            // 处理转交操作：使用transferTo字段构造comment
            String comment = request.getComment();
            if ("TRANSFER".equals(request.getAction()) && request.getTransferTo() != null) {
                comment = "transfer:" + request.getTransferTo();
            }

            Map<String, Object> result = approvalFlowService.handleApproval(
                    request.getRecordId(),
                    request.getAction(),
                    currentUserId, // 使用登录用户ID
                    comment
            );

            // 业务回调已在 ApprovalFlowService.handleApproval() -> processAfterApproval() 中统一处理

            return ApiResponse.success(result, "审批处理成功");
        } catch (IllegalArgumentException e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 根据action获取对应的execute权限码
     */
    private String getExecutePermissionForAction(String action) {
        if (action == null) {
            return null;
        }
        switch (action.toUpperCase()) {
            case "APPROVE":
                return "approval.execute.approve.ALL";
            case "REJECT":
                return "approval.execute.reject.ALL";
            case "TRANSFER":
                return "approval.execute.transfer.ALL";
            default:
                return null;
        }
    }

    /**
     * 取消审批 - 只信任登录态用户
     */
    @PostMapping("/cancel")
    @RequirePermission("approval.index.cancel.ALL")
    public ApiResponse<Void> cancelApproval(
            @RequestBody ApprovalCancelRequest request,
            HttpServletRequest httpRequest) {
        try {
            // 只信任登录态用户，忽略请求体中的operatorId
            Long currentUserId = getCurrentUserId(httpRequest);
            if (currentUserId == null) {
                return ApiResponse.error(401, "未获取到用户信息");
            }

            approvalFlowService.cancelApproval(request.getRecordId(), currentUserId);
            return ApiResponse.success(null, "审批已取消");
        } catch (IllegalArgumentException e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 批量审批 - 只信任登录态用户
     * 使用独立的 approval.index.batch.ALL 权限（区别于 batch.handle.ALL）
     * 支持批量通过/拒绝，返回成功/失败明细
     */
    @PostMapping("/batch")
    @RequirePermission("approval.index.batch.ALL")
    public ApiResponse<Map<String, Object>> batchApproval(
            @RequestBody ApprovalBatchRequest request,
            HttpServletRequest httpRequest) {
        try {
            Long currentUserId = getCurrentUserId(httpRequest);
            if (currentUserId == null) {
                return ApiResponse.error(401, "未获取到用户信息");
            }

            if (request.getRecordIds() == null || request.getRecordIds().isEmpty()) {
                return ApiResponse.error(400, "请选择要处理的审批记录");
            }

            Map<String, Object> result = approvalFlowService.batchHandleApproval(
                    request.getRecordIds(),
                    request.getAction(),
                    currentUserId,
                    request.getComment()
            );

            return ApiResponse.success(result, "批量审批完成");
        } catch (Exception e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 批量转交审批 - 只信任登录态用户
     * 使用独立的 approval.index.batch.transfer.ALL 权限
     */
    @PostMapping("/batch-transfer")
    @RequirePermission("approval.index.batch.transfer.ALL")
    public ApiResponse<Map<String, Object>> batchTransferApproval(
            @RequestBody ApprovalBatchTransferRequest request,
            HttpServletRequest httpRequest) {
        try {
            Long currentUserId = getCurrentUserId(httpRequest);
            if (currentUserId == null) {
                return ApiResponse.error(401, "未获取到用户信息");
            }

            if (request.getRecordIds() == null || request.getRecordIds().isEmpty()) {
                return ApiResponse.error(400, "请选择要转交的审批记录");
            }

            if (request.getTransferTo() == null) {
                return ApiResponse.error(400, "转交目标用户不能为空");
            }

            // 使用transferTo字段构造comment
            String comment = "transfer:" + request.getTransferTo();
            if (request.getComment() != null && !request.getComment().isBlank()) {
                comment = request.getComment() + " -> " + comment;
            }

            Map<String, Object> result = approvalFlowService.batchHandleApproval(
                    request.getRecordIds(),
                    "TRANSFER",
                    currentUserId,
                    comment
            );

            return ApiResponse.success(result, "批量转交完成");
        } catch (Exception e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 委托审批 - 只信任登录态用户
     * 使用独立的 approval.index.delegate.ALL 权限
     */
    @PostMapping("/delegate")
    @RequirePermission("approval.index.delegate.ALL")
    public ApiResponse<Map<String, Object>> delegateApproval(
            @RequestBody ApprovalDelegateRequest request,
            HttpServletRequest httpRequest) {
        try {
            Long currentUserId = getCurrentUserId(httpRequest);
            if (currentUserId == null) {
                return ApiResponse.error(401, "未获取到用户信息");
            }

            if (request.getRecordId() == null) {
                return ApiResponse.error(400, "审批记录ID不能为空");
            }

            if (request.getDelegateTo() == null) {
                return ApiResponse.error(400, "委托目标用户不能为空");
            }

            // 构造委托comment
            String comment = "delegate:" + request.getDelegateTo();
            if (request.getReason() != null && !request.getReason().isBlank()) {
                comment = request.getReason() + " -> " + comment;
            }

            Map<String, Object> result = approvalFlowService.handleApproval(
                    request.getRecordId(),
                    "DELEGATE",
                    currentUserId,
                    comment
            );

            return ApiResponse.success(result, "审批委托成功");
        } catch (IllegalArgumentException e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 获取审批记录详情
     */
    @GetMapping("/records/{id}")
    @RequirePermission("approval.record.view.ALL")
    public ApiResponse<Map<String, Object>> getRecordById(@PathVariable Long id) {
        Map<String, Object> record = approvalFlowService.getRecordById(id);
        if (record == null) {
            return ApiResponse.error(404, "审批记录不存在");
        }
        return ApiResponse.success(record);
    }

    /**
     * 获取审批历史
     */
    @GetMapping("/records/{recordId}/history")
    @RequirePermission("approval.record.view.ALL")
    public ApiResponse<List<SysApprovalHistory>> getApprovalHistory(@PathVariable Long recordId) {
        return ApiResponse.success(approvalFlowService.getApprovalHistory(recordId));
    }

    /**
     * 添加审批意见（不改变审批状态）
     * 使用独立的 approval.comment.add.ALL 权限
     */
    @PostMapping("/records/{recordId}/comment")
    @RequirePermission("approval.comment.add.ALL")
    public ApiResponse<SysApprovalHistory> addComment(
            @PathVariable Long recordId,
            @RequestBody ApprovalCommentRequest request,
            HttpServletRequest httpRequest) {
        try {
            Long currentUserId = getCurrentUserId(httpRequest);
            if (currentUserId == null) {
                return ApiResponse.error(401, "未获取到用户信息");
            }

            if (request.getComment() == null || request.getComment().isBlank()) {
                return ApiResponse.error(400, "意见内容不能为空");
            }

            SysApprovalHistory history = approvalFlowService.addComment(
                    recordId,
                    currentUserId,
                    request.getComment()
            );

            return ApiResponse.success(history, "意见添加成功");
        } catch (IllegalArgumentException e) {
            return ApiResponse.error(400, e.getMessage());
        }
    }

    /**
     * 从请求属性中获取当前用户ID
     */
    private Long getCurrentUserId(HttpServletRequest request) {
        Object userIdObj = request.getAttribute("userId");
        if (userIdObj instanceof Long) {
            return (Long) userIdObj;
        } else if (userIdObj instanceof Integer) {
            return ((Integer) userIdObj).longValue();
        }
        return null;
    }

    /**
     * 提交审批请求体
     */
    public static class ApprovalSubmitRequest {
        private Long flowId;
        private String bizType;
        private Long bizId;
        private String title;
        private Long applicantId;
        private String applyReason;

        public Long getFlowId() { return flowId; }
        public void setFlowId(Long flowId) { this.flowId = flowId; }
        public String getBizType() { return bizType; }
        public void setBizType(String bizType) { this.bizType = bizType; }
        public Long getBizId() { return bizId; }
        public void setBizId(Long bizId) { this.bizId = bizId; }
        public String getTitle() { return title; }
        public void setTitle(String title) { this.title = title; }
        public Long getApplicantId() { return applicantId; }
        public void setApplicantId(Long applicantId) { this.applicantId = applicantId; }
        public String getApplyReason() { return applyReason; }
        public void setApplyReason(String applyReason) { this.applyReason = applyReason; }
    }

    /**
     * 通过触发事件提交审批请求体
     */
    public static class ApprovalSubmitByEventRequest {
        private String triggerEvent;
        private String bizType;
        private Long bizId;
        private String title;
        private Long applicantId;
        private String applyReason;

        public String getTriggerEvent() { return triggerEvent; }
        public void setTriggerEvent(String triggerEvent) { this.triggerEvent = triggerEvent; }
        public String getBizType() { return bizType; }
        public void setBizType(String bizType) { this.bizType = bizType; }
        public Long getBizId() { return bizId; }
        public void setBizId(Long bizId) { this.bizId = bizId; }
        public String getTitle() { return title; }
        public void setTitle(String title) { this.title = title; }
        public Long getApplicantId() { return applicantId; }
        public void setApplicantId(Long applicantId) { this.applicantId = applicantId; }
        public String getApplyReason() { return applyReason; }
        public void setApplyReason(String applyReason) { this.applyReason = applyReason; }
    }

    /**
     * 审批处理请求体
     */
    public static class ApprovalHandleRequest {
        private Long recordId;
        private String action;
        private Long operatorId;
        private String comment;
        private Long transferTo;  // 转交目标用户ID

        public Long getRecordId() { return recordId; }
        public void setRecordId(Long recordId) { this.recordId = recordId; }
        public String getAction() { return action; }
        public void setAction(String action) { this.action = action; }
        public Long getOperatorId() { return operatorId; }
        public void setOperatorId(Long operatorId) { this.operatorId = operatorId; }
        public String getComment() { return comment; }
        public void setComment(String comment) { this.comment = comment; }
        public Long getTransferTo() { return transferTo; }
        public void setTransferTo(Long transferTo) { this.transferTo = transferTo; }
    }

    /**
     * 取消审批请求体
     */
    public static class ApprovalCancelRequest {
        private Long recordId;
        private Long operatorId;

        public Long getRecordId() { return recordId; }
        public void setRecordId(Long recordId) { this.recordId = recordId; }
        public Long getOperatorId() { return operatorId; }
        public void setOperatorId(Long operatorId) { this.operatorId = operatorId; }
    }

    /**
     * 批量审批处理请求体
     */
    public static class ApprovalBatchHandleRequest {
        private List<Long> recordIds;
        private String action;
        private String comment;

        public List<Long> getRecordIds() { return recordIds; }
        public void setRecordIds(List<Long> recordIds) { this.recordIds = recordIds; }
        public String getAction() { return action; }
        public void setAction(String action) { this.action = action; }
        public String getComment() { return comment; }
        public void setComment(String comment) { this.comment = comment; }
    }

    /**
     * 批量审批请求体（使用 approval.index.batch.ALL 权限）
     */
    public static class ApprovalBatchRequest {
        private List<Long> recordIds;
        private String action;
        private String comment;

        public List<Long> getRecordIds() { return recordIds; }
        public void setRecordIds(List<Long> recordIds) { this.recordIds = recordIds; }
        public String getAction() { return action; }
        public void setAction(String action) { this.action = action; }
        public String getComment() { return comment; }
        public void setComment(String comment) { this.comment = comment; }
    }

    /**
     * 批量转交审批请求体（使用 approval.index.batch.transfer.ALL 权限）
     */
    public static class ApprovalBatchTransferRequest {
        private List<Long> recordIds;
        private Long transferTo;
        private String comment;

        public List<Long> getRecordIds() { return recordIds; }
        public void setRecordIds(List<Long> recordIds) { this.recordIds = recordIds; }
        public Long getTransferTo() { return transferTo; }
        public void setTransferTo(Long transferTo) { this.transferTo = transferTo; }
        public String getComment() { return comment; }
        public void setComment(String comment) { this.comment = comment; }
    }

    /**
     * 委托审批请求体（使用 approval.index.delegate.ALL 权限）
     */
    public static class ApprovalDelegateRequest {
        private Long recordId;
        private Long delegateTo;
        private String reason;

        public Long getRecordId() { return recordId; }
        public void setRecordId(Long recordId) { this.recordId = recordId; }
        public Long getDelegateTo() { return delegateTo; }
        public void setDelegateTo(Long delegateTo) { this.delegateTo = delegateTo; }
        public String getReason() { return reason; }
        public void setReason(String reason) { this.reason = reason; }
    }

    /**
     * 添加审批意见请求体（使用 approval.comment.add.ALL 权限）
     */
    public static class ApprovalCommentRequest {
        private String comment;

        public String getComment() { return comment; }
        public void setComment(String comment) { this.comment = comment; }
    }
}
