using System.ComponentModel.DataAnnotations;

namespace MilitaryTrainingManagement.Models.Entities;

/// <summary>
/// 配额分配实体
/// </summary>
public class AllocationDistribution
{
    public int Id { get; set; }

    /// <summary>
    /// 关联的物资配额ID
    /// </summary>
    public int AllocationId { get; set; }

    /// <summary>
    /// 关联的物资配额
    /// </summary>
    public MaterialAllocation Allocation { get; set; } = null!;

    /// <summary>
    /// 目标单位ID
    /// </summary>
    public int TargetUnitId { get; set; }

    /// <summary>
    /// 目标单位
    /// </summary>
    public OrganizationalUnit TargetUnit { get; set; } = null!;

    /// <summary>
    /// 单位指标
    /// </summary>
    [Range(0, double.MaxValue, ErrorMessage = "单位配额不能为负数")]
    public decimal UnitQuota { get; set; }

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

    /// <summary>
    /// 完成率 (实际完成 / 单位指标)
    /// </summary>
    public decimal CompletionRate => UnitQuota > 0 && ActualCompletion.HasValue 
        ? ActualCompletion.Value / UnitQuota 
        : 0;

    /// <summary>
    /// 上报时间
    /// </summary>
    public DateTime? ReportedAt { get; set; }

    /// <summary>
    /// 上报人ID
    /// </summary>
    public int? ReportedByUserId { get; set; }

    /// <summary>
    /// 上报人
    /// </summary>
    public UserAccount? ReportedByUser { get; set; }
    
    /// <summary>
    /// 是否已被上级审批
    /// </summary>
    public bool IsApproved { get; set; } = false;
    
    /// <summary>
    /// 审批时间
    /// </summary>
    public DateTime? ApprovedAt { get; set; }
    
    /// <summary>
    /// 审批人ID
    /// </summary>
    public int? ApprovedByUserId { get; set; }
    
    /// <summary>
    /// 审批人
    /// </summary>
    public UserAccount? ApprovedByUser { get; set; }
}
