using System.ComponentModel.DataAnnotations;

namespace MilitaryTrainingManagement.Models.DTOs;

/// <summary>
/// 提交上报请求
/// </summary>
public class SubmitReportRequest
{
    /// <summary>
    /// 分配记录ID
    /// </summary>
    [Required(ErrorMessage = "分配记录ID为必填项")]
    public int DistributionId { get; set; }

    /// <summary>
    /// 实际完成数量
    /// </summary>
    [Required(ErrorMessage = "实际完成数量为必填项")]
    [Range(0, double.MaxValue, ErrorMessage = "实际完成数量不能为负数")]
    public decimal ActualCompletion { get; set; }
}

/// <summary>
/// 上报记录响应
/// </summary>
public class ReportResponse
{
    public int Id { get; set; }
    public int AllocationId { get; set; }
    public string Category { get; set; } = string.Empty;
    public string MaterialName { get; set; } = string.Empty;
    public string Unit { get; set; } = string.Empty;
    public int TargetUnitId { get; set; }
    public string TargetUnitName { get; set; } = string.Empty;
    public decimal UnitQuota { get; set; }
    public decimal? ActualCompletion { get; set; }
    public decimal CompletionRate { get; set; }
    public DateTime? ReportedAt { get; set; }
    public int? ReportedByUserId { get; set; }
    public string? ReportedByUserName { get; set; }
}

/// <summary>
/// 汇总数据响应
/// </summary>
public class AggregatedReportResponse
{
    public int AllocationId { get; set; }
    public string Category { get; set; } = string.Empty;
    public string MaterialName { get; set; } = string.Empty;
    public string Unit { get; set; } = string.Empty;
    public decimal TotalQuota { get; set; }
    public decimal TotalActualCompletion { get; set; }
    public decimal OverallCompletionRate { get; set; }
    public List<UnitReportSummary> UnitSummaries { get; set; } = new();
}

/// <summary>
/// 单位上报汇总
/// </summary>
public class UnitReportSummary
{
    public int UnitId { get; set; }
    public string UnitName { get; set; } = string.Empty;
    public string UnitLevel { get; set; } = string.Empty;
    public decimal UnitQuota { get; set; }
    public decimal? ActualCompletion { get; set; }
    public decimal CompletionRate { get; set; }
    public DateTime? ReportedAt { get; set; }
    public string? ReportedByUserName { get; set; }
    
    // 新增字段：用于按单位汇总上报数据
    public decimal TotalReported { get; set; }
    public int ReportCount { get; set; }
    public DateTime? LastReportedAt { get; set; }
}

/// <summary>
/// 层级汇总数据响应
/// </summary>
public class HierarchicalAggregatedResponse
{
    public int UnitId { get; set; }
    public string UnitName { get; set; } = string.Empty;
    public string UnitLevel { get; set; } = string.Empty;
    public decimal TotalQuota { get; set; }
    public decimal TotalActualCompletion { get; set; }
    public decimal OverallCompletionRate { get; set; }
    public List<AllocationAggregation> AllocationAggregations { get; set; } = new();
    public List<SubordinateUnitSummary> SubordinateSummaries { get; set; } = new();
}

/// <summary>
/// 配额汇总
/// </summary>
public class AllocationAggregation
{
    public int AllocationId { get; set; }
    public string Category { get; set; } = string.Empty;
    public string MaterialName { get; set; } = string.Empty;
    public string Unit { get; set; } = string.Empty;
    public decimal TotalQuota { get; set; }
    public decimal TotalActualCompletion { get; set; }
    public decimal CompletionRate { get; set; }
}

/// <summary>
/// 下级单位汇总
/// </summary>
public class SubordinateUnitSummary
{
    public int UnitId { get; set; }
    public string UnitName { get; set; } = string.Empty;
    public string UnitLevel { get; set; } = string.Empty;
    public decimal TotalQuota { get; set; }
    public decimal TotalActualCompletion { get; set; }
    public decimal CompletionRate { get; set; }
}

/// <summary>
/// 单位消耗统计（按时间范围）
/// </summary>
public class UnitConsumptionStat
{
    public int UnitId { get; set; }
    public string UnitName { get; set; } = string.Empty;
    public string UnitLevel { get; set; } = string.Empty;
    public decimal UnitQuota { get; set; }
    public decimal TotalConsumed { get; set; }
    public decimal CompletionRate { get; set; }
    public int ReportCount { get; set; }
}
