using System;
using System.Collections.Generic;

namespace NPP.SmartSchedue.Api.Contracts.Services.Integration.Output;

/// <summary>
/// 完成整合记录结果
/// 包含完成操作的详细结果和统计信息
/// </summary>
public class CompleteIntegrationRecordResult
{
    /// <summary>
    /// 完成操作是否成功
    /// </summary>
    public bool IsSuccess { get; set; }

    /// <summary>
    /// 完成成功消息
    /// </summary>
    public string SuccessMessage { get; set; } = string.Empty;

    /// <summary>
    /// 完成失败消息
    /// </summary>
    public string ErrorMessage { get; set; } = string.Empty;

    /// <summary>
    /// 整合记录ID
    /// </summary>
    public long IntegrationRecordId { get; set; }

    /// <summary>
    /// 完成时间
    /// </summary>
    public DateTime CompletedTime { get; set; }

    /// <summary>
    /// 整合批次编码
    /// </summary>
    public string IntegrationBatchCode { get; set; } = string.Empty;

    /// <summary>
    /// 完成验证结果
    /// 验证所有任务是否都已完成
    /// </summary>
    public CompleteValidationResult ValidationResult { get; set; } = new();

    /// <summary>
    /// 完成统计信息
    /// </summary>
    public CompleteStatistics Statistics { get; set; } = new();

    /// <summary>
    /// 警告信息列表
    /// </summary>
    public List<string> WarningMessages { get; set; } = new();
}

/// <summary>
/// 完成验证结果
/// </summary>
public class CompleteValidationResult
{
    /// <summary>
    /// 验证是否通过
    /// </summary>
    public bool IsValid { get; set; }

    /// <summary>
    /// 验证时间
    /// </summary>
    public DateTime ValidationTime { get; set; }

    /// <summary>
    /// 总任务数
    /// </summary>
    public int TotalTaskCount { get; set; }

    /// <summary>
    /// 已完成任务数
    /// </summary>
    public int CompletedTaskCount { get; set; }

    /// <summary>
    /// 未完成任务数
    /// </summary>
    public int IncompleteTaskCount { get; set; }

    /// <summary>
    /// 未完成任务列表
    /// </summary>
    public List<IncompleteTaskInfo> IncompleteTasks { get; set; } = new();

    /// <summary>
    /// 完成率
    /// </summary>
    public decimal CompletionRate { get; set; }

    /// <summary>
    /// 验证详情
    /// </summary>
    public string ValidationDetails { get; set; } = string.Empty;
}

/// <summary>
/// 未完成任务信息
/// </summary>
public class IncompleteTaskInfo
{
    /// <summary>
    /// 任务ID
    /// </summary>
    public long TaskId { get; set; }

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

    /// <summary>
    /// 当前状态
    /// </summary>
    public string CurrentStatus { get; set; } = string.Empty;

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

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

    /// <summary>
    /// 计划工作日期
    /// </summary>
    public DateTime WorkOrderDate { get; set; }

    /// <summary>
    /// 未完成原因
    /// </summary>
    public string IncompleteReason { get; set; } = string.Empty;
}

/// <summary>
/// 完成统计信息
/// </summary>
public class CompleteStatistics
{
    /// <summary>
    /// 整合记录持续时间（从发布到完成的毫秒数）
    /// </summary>
    public long IntegrationDurationMilliseconds { get; set; }

    /// <summary>
    /// 平均任务执行时间（毫秒）
    /// </summary>
    public long AverageTaskExecutionTime { get; set; }

    /// <summary>
    /// 最快完成任务时间（毫秒）
    /// </summary>
    public long FastestTaskTime { get; set; }

    /// <summary>
    /// 最慢完成任务时间（毫秒）
    /// </summary>
    public long SlowestTaskTime { get; set; }

    /// <summary>
    /// 人员效率统计
    /// </summary>
    public List<PersonnelEfficiencyStats> PersonnelEfficiencyStats { get; set; } = new();

    /// <summary>
    /// 设备利用率统计
    /// </summary>
    public List<EquipmentUtilizationStats> EquipmentUtilizationStats { get; set; } = new();

    /// <summary>
    /// 整体效率评分（0-100）
    /// </summary>
    public int OverallEfficiencyScore { get; set; }
}

/// <summary>
/// 人员效率统计
/// </summary>
public class PersonnelEfficiencyStats
{
    /// <summary>
    /// 人员ID
    /// </summary>
    public long PersonnelId { get; set; }

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

    /// <summary>
    /// 完成任务数
    /// </summary>
    public int CompletedTaskCount { get; set; }

    /// <summary>
    /// 平均任务耗时（毫秒）
    /// </summary>
    public long AverageTaskTime { get; set; }

    /// <summary>
    /// 效率评分（0-100）
    /// </summary>
    public int EfficiencyScore { get; set; }

    /// <summary>
    /// 任务质量评分（0-100）
    /// </summary>
    public int QualityScore { get; set; }
}

/// <summary>
/// 设备利用率统计
/// </summary>
public class EquipmentUtilizationStats
{
    /// <summary>
    /// 设备ID
    /// </summary>
    public long EquipmentId { get; set; }

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

    /// <summary>
    /// 完成任务数
    /// </summary>
    public int CompletedTaskCount { get; set; }

    /// <summary>
    /// 总使用时间（毫秒）
    /// </summary>
    public long TotalUsageTime { get; set; }

    /// <summary>
    /// 实际利用率（百分比）
    /// </summary>
    public decimal ActualUtilizationRate { get; set; }

    /// <summary>
    /// 计划利用率（百分比）
    /// </summary>
    public decimal PlannedUtilizationRate { get; set; }

    /// <summary>
    /// 利用率达成度（百分比）
    /// </summary>
    public decimal UtilizationAchievementRate { get; set; }
}