using System;
using System.Collections.Generic;

namespace NPP.SmartSchedue.Api.Contracts.Domain.Integration;

/// <summary>
/// 整合记录快照数据
/// 用于记录整合记录在特定时刻的完整状态
/// 
/// 业务价值：
/// 1. 状态追踪：记录整合记录在关键时刻的完整状态
/// 2. 变更对比：支持前后状态的对比分析
/// 3. 回滚支持：为状态回滚提供数据基础
/// 4. 审计完整：提供完整的状态变更审计信息
/// </summary>
public class IntegrationSnapshot
{
    /// <summary>
    /// 快照时间
    /// </summary>
    public DateTime SnapshotTime { get; set; } = DateTime.Now;

    /// <summary>
    /// 快照类型
    /// </summary>
    public string SnapshotType { get; set; } = string.Empty;

    /// <summary>
    /// 整合记录状态
    /// </summary>
    public string RecordStatus { get; set; } = string.Empty;

    /// <summary>
    /// 任务状态快照
    /// 记录所有相关任务在快照时刻的状态
    /// </summary>
    public List<TaskStatusSnapshot> TaskStatusSnapshots { get; set; } = new();

    /// <summary>
    /// 人员分配快照
    /// 记录人员分配在快照时刻的状态
    /// </summary>
    public List<PersonnelAssignmentSnapshot> PersonnelAssignmentSnapshots { get; set; } = new();

    /// <summary>
    /// 设备分配快照
    /// 记录设备分配在快照时刻的状态
    /// </summary>
    public List<EquipmentAssignmentSnapshot> EquipmentAssignmentSnapshots { get; set; } = new();

    /// <summary>
    /// 统计信息快照
    /// </summary>
    public StatisticsSnapshot StatisticsSnapshot { get; set; } = new();

    /// <summary>
    /// 备注信息
    /// </summary>
    public string Remarks { get; set; } = string.Empty;
}

/// <summary>
/// 任务状态快照
/// </summary>
public class TaskStatusSnapshot
{
    /// <summary>
    /// 任务ID
    /// </summary>
    public long TaskId { get; set; }

    /// <summary>
    /// 任务代码
    /// </summary>
    public string TaskCode { get; set; } = string.Empty;

    /// <summary>
    /// 任务状态
    /// </summary>
    public string Status { get; set; } = string.Empty;

    /// <summary>
    /// 分配的人员ID
    /// </summary>
    public long? AssignedPersonnelId { get; set; }

    /// <summary>
    /// 分配的人员姓名
    /// </summary>
    public string AssignedPersonnelName { get; set; } = string.Empty;

    /// <summary>
    /// 分配的设备ID
    /// </summary>
    public long? AssignedEquipmentId { get; set; }

    /// <summary>
    /// 分配的设备名称
    /// </summary>
    public string AssignedEquipmentName { get; set; } = string.Empty;

    /// <summary>
    /// 快照时间
    /// </summary>
    public DateTime SnapshotTime { get; set; }
}

/// <summary>
/// 人员分配快照
/// </summary>
public class PersonnelAssignmentSnapshot
{
    /// <summary>
    /// 人员ID
    /// </summary>
    public long PersonnelId { get; set; }

    /// <summary>
    /// 人员姓名
    /// </summary>
    public string PersonnelName { get; set; } = string.Empty;

    /// <summary>
    /// 分配的任务ID列表
    /// </summary>
    public List<long> AssignedTaskIds { get; set; } = new();

    /// <summary>
    /// 工作负载百分比
    /// </summary>
    public decimal WorkloadPercentage { get; set; }

    /// <summary>
    /// 快照时间
    /// </summary>
    public DateTime SnapshotTime { get; set; }
}

/// <summary>
/// 设备分配快照
/// </summary>
public class EquipmentAssignmentSnapshot
{
    /// <summary>
    /// 设备ID
    /// </summary>
    public long EquipmentId { get; set; }

    /// <summary>
    /// 设备名称
    /// </summary>
    public string EquipmentName { get; set; } = string.Empty;

    /// <summary>
    /// 分配的任务ID列表
    /// </summary>
    public List<long> AssignedTaskIds { get; set; } = new();

    /// <summary>
    /// 利用率百分比
    /// </summary>
    public decimal UtilizationRate { get; set; }

    /// <summary>
    /// 快照时间
    /// </summary>
    public DateTime SnapshotTime { get; set; }
}

/// <summary>
/// 统计信息快照
/// </summary>
public class StatisticsSnapshot
{
    /// <summary>
    /// 总任务数
    /// </summary>
    public int TotalTaskCount { get; set; }

    /// <summary>
    /// 成功任务数
    /// </summary>
    public int SuccessTaskCount { get; set; }

    /// <summary>
    /// 失败任务数
    /// </summary>
    public int FailedTaskCount { get; set; }

    /// <summary>
    /// 成功率
    /// </summary>
    public decimal SuccessRate { get; set; }

    /// <summary>
    /// 人员公平性评分
    /// </summary>
    public int PersonnelFairnessScore { get; set; }

    /// <summary>
    /// 设备利用率
    /// </summary>
    public decimal EquipmentUtilizationRate { get; set; }

    /// <summary>
    /// 快照时间
    /// </summary>
    public DateTime SnapshotTime { get; set; }
}