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

namespace MilitaryTrainingManagement.Services.Interfaces;

/// <summary>
/// 上报服务接口
/// </summary>
public interface IReportingService
{
    /// <summary>
    /// 根据ID获取分配记录
    /// </summary>
    Task<AllocationDistribution?> GetDistributionByIdAsync(int id);

    /// <summary>
    /// 获取单位的分配记录
    /// </summary>
    Task<IEnumerable<AllocationDistribution>> GetDistributionsByUnitAsync(int unitId);

    /// <summary>
    /// 提交上报数据
    /// </summary>
    Task<AllocationDistribution> SubmitReportAsync(int distributionId, decimal actualCompletion, int reportedByUserId);

    /// <summary>
    /// 计算完成率
    /// </summary>
    Task<decimal> CalculateCompletionRateAsync(int distributionId);

    /// <summary>
    /// 计算完成率（纯函数版本，用于属性测试）
    /// </summary>
    decimal CalculateCompletionRate(decimal? actualCompletion, decimal unitQuota);

    /// <summary>
    /// 获取汇总数据（包含下级单位，应用可见性过滤）
    /// </summary>
    Task<IEnumerable<AllocationDistribution>> GetAggregatedDataAsync(int unitId, OrganizationalLevel userLevel);

    /// <summary>
    /// 获取层级汇总数据
    /// </summary>
    Task<HierarchicalAggregatedResponse> GetHierarchicalAggregatedDataAsync(int unitId);

    /// <summary>
    /// 获取层级汇总数据（应用可见性过滤）
    /// </summary>
    Task<HierarchicalAggregatedResponse> GetHierarchicalAggregatedDataAsync(int unitId, OrganizationalLevel userLevel);

    /// <summary>
    /// 获取按配额分组的汇总数据
    /// </summary>
    Task<IEnumerable<AggregatedReportResponse>> GetAggregatedByAllocationAsync(int unitId);

    /// <summary>
    /// 获取直接下级单位的汇总数据
    /// </summary>
    Task<IEnumerable<SubordinateUnitSummary>> GetDirectSubordinateSummariesAsync(int unitId);

    /// <summary>
    /// 检查用户是否有权限查看指定单位的数据（使用可见性范围）
    /// </summary>
    Task<bool> CanViewUnitDataAsync(int userUnitId, int targetUnitId, OrganizationalLevel userLevel);

    /// <summary>
    /// 获取详细上报记录（包含时间戳和上报人员，应用可见性过滤）
    /// </summary>
    Task<IEnumerable<ReportResponse>> GetDetailedReportsAsync(int unitId, OrganizationalLevel userLevel);
}
