using MilitaryTrainingManagement.Models.Entities;
using MilitaryTrainingManagement.Models.Enums;

namespace MilitaryTrainingManagement.Services.Interfaces;

/// <summary>
/// 审批工作流服务接口
/// </summary>
public interface IWorkflowService
{
    /// <summary>
    /// 根据ID获取审批请求
    /// </summary>
    Task<ApprovalRequest?> GetByIdAsync(int id);
    
    /// <summary>
    /// 获取待处理的审批请求（师团级别可见）
    /// </summary>
    Task<IEnumerable<ApprovalRequest>> GetPendingRequestsAsync();
    
    /// <summary>
    /// 获取所有审批请求
    /// </summary>
    Task<IEnumerable<ApprovalRequest>> GetAllRequestsAsync(ApprovalStatus? status = null);
    
    /// <summary>
    /// 获取指定组织单位的审批请求
    /// </summary>
    Task<IEnumerable<ApprovalRequest>> GetRequestsByUnitAsync(int unitId, ApprovalStatus? status = null);
    
    /// <summary>
    /// 获取指定类型的审批请求
    /// </summary>
    Task<IEnumerable<ApprovalRequest>> GetRequestsByTypeAsync(ApprovalRequestType type, ApprovalStatus? status = null);
    
    /// <summary>
    /// 创建修改请求
    /// </summary>
    Task<ApprovalRequest> CreateModificationRequestAsync(
        ApprovalRequestType type, 
        int targetEntityId,
        int requestedByUserId, 
        int requestedByUnitId,
        string reason, 
        string originalData, 
        string requestedChanges);
    
    /// <summary>
    /// 审批通过请求
    /// </summary>
    Task<ApprovalRequest> ApproveAsync(int requestId, int reviewedByUserId, string? comments);
    
    /// <summary>
    /// 拒绝请求
    /// </summary>
    Task<ApprovalRequest> RejectAsync(int requestId, int reviewedByUserId, string? comments);
    
    /// <summary>
    /// 检查记录是否已被审批（不可直接修改）
    /// </summary>
    Task<bool> IsRecordApprovedAsync(ApprovalRequestType type, int entityId);
    
    /// <summary>
    /// 检查是否存在待处理的修改请求
    /// </summary>
    Task<bool> HasPendingModificationRequestAsync(ApprovalRequestType type, int entityId);
    
    /// <summary>
    /// 验证用户是否有权限审批请求（仅师团级别）
    /// </summary>
    Task<bool> CanUserApproveAsync(int userId);
}
