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

namespace MilitaryTrainingManagement.Services.Interfaces;

/// <summary>
/// 数据汇总服务接口
/// 需求：3.4, 3.5, 4.1, 4.2
/// </summary>
public interface IDataAggregatorService
{
    /// <summary>
    /// 汇总指定单位及其下级的所有分配数据
    /// </summary>
    Task<IEnumerable<AllocationDistribution>> AggregateDistributionsAsync(int unitId);

    /// <summary>
    /// 计算层级汇总数据
    /// 需求4.1：显示所有下级单位的总配额、实际完成和整体完成率
    /// </summary>
    Task<HierarchicalAggregatedResponse> CalculateHierarchicalAggregationAsync(int unitId);

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

    /// <summary>
    /// 获取直接下级单位汇总
    /// 需求4.2：显示直接下级单位的详细配额、实际完成和完成率数据
    /// </summary>
    Task<IEnumerable<SubordinateUnitSummary>> GetDirectSubordinateSummariesAsync(int unitId);

    /// <summary>
    /// 汇总单位的总配额
    /// </summary>
    decimal SumTotalQuota(IEnumerable<AllocationDistribution> distributions);

    /// <summary>
    /// 汇总单位的总实际完成
    /// </summary>
    decimal SumTotalActualCompletion(IEnumerable<AllocationDistribution> distributions);

    /// <summary>
    /// 计算整体完成率
    /// </summary>
    decimal CalculateOverallCompletionRate(decimal totalQuota, decimal totalActualCompletion);

    /// <summary>
    /// 验证汇总数据一致性（用于属性测试）
    /// 属性4：层级数据汇总 - 显示的汇总数据应等于所有直接下级单位数据的总和
    /// </summary>
    bool ValidateAggregationConsistency(
        decimal parentTotalQuota,
        decimal parentTotalActualCompletion,
        IEnumerable<SubordinateUnitSummary> subordinateSummaries);
}
