using System;
using System.Collections.Generic;
using NPP.SmartSchedue.Api.Contracts.Services.Time.Output;
using NPP.SmartSchedue.Api.Contracts.Services.Work.Output;

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

/// <summary>
/// 发布整合记录结果
/// 包含发布操作的详细结果和状态信息
/// </summary>
public class PublishIntegrationRecordResult
{
    /// <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 PublishedTime { get; set; }

    /// <summary>
    /// 发布的批次编码
    /// </summary>
    public string IntegrationBatchCode { get; set; } = string.Empty;

    /// <summary>
    /// 成功发布的任务详情
    /// </summary>
    public List<PublishedTaskDetail> PublishedTasks { get; set; } = new();

    /// <summary>
    /// 发布失败的任务详情
    /// </summary>
    public List<FailedPublishTaskDetail> FailedPublishTasks { get; set; } = new();

    /// <summary>
    /// 任务状态更新结果
    /// 记录任务状态同步的详细情况
    /// </summary>
    public TaskStatusSyncResult TaskStatusSyncResult { get; set; } = new();

    /// <summary>
    /// 发布前验证结果
    /// 包含所有预发布检查的结果
    /// </summary>
    public PublishValidationResult ValidationResult { get; set; } = new();

    /// <summary>
    /// 通知发送结果
    /// 记录发布后通知的发送情况
    /// </summary>
    public List<IntegrationNotificationResult> NotificationResults { get; set; } = new();

    /// <summary>
    /// 发布统计信息
    /// </summary>
    public PublishStatistics Statistics { get; set; } = new();

    /// <summary>
    /// 警告信息列表
    /// 发布成功但存在需要注意的问题
    /// </summary>
    public List<string> WarningMessages { get; set; } = new();
}

/// <summary>
/// 已发布任务详情
/// </summary>
public class PublishedTaskDetail
{
    /// <summary>
    /// 任务ID
    /// </summary>
    public long TaskId { get; set; }

    /// <summary>
    /// 任务代码
    /// </summary>
    public string TaskCode { 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 string PreviousStatus { get; set; } = string.Empty;

    /// <summary>
    /// 发布后状态
    /// </summary>
    public string CurrentStatus { get; set; } = string.Empty;

    /// <summary>
    /// 任务发布时间
    /// </summary>
    public DateTime PublishTime { get; set; }
}

/// <summary>
/// 发布失败任务详情
/// </summary>
public class FailedPublishTaskDetail
{
    /// <summary>
    /// 任务ID
    /// </summary>
    public long TaskId { get; set; }

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

    /// <summary>
    /// 失败原因
    /// </summary>
    public string FailureReason { get; set; } = string.Empty;

    /// <summary>
    /// 详细错误信息
    /// </summary>
    public List<string> DetailedErrors { get; set; } = new();

    /// <summary>
    /// 解决建议
    /// </summary>
    public List<string> Suggestions { get; set; } = new();
}

/// <summary>
/// 任务状态同步结果
/// </summary>
public class TaskStatusSyncResult
{
    /// <summary>
    /// 同步是否完全成功
    /// </summary>
    public bool IsFullySuccessful { get; set; }

    /// <summary>
    /// 成功同步的任务数量
    /// </summary>
    public int SuccessfulSyncCount { get; set; }

    /// <summary>
    /// 同步失败的任务数量
    /// </summary>
    public int FailedSyncCount { get; set; }

    /// <summary>
    /// 同步详细结果
    /// </summary>
    public List<TaskSyncDetail> SyncDetails { get; set; } = new();

    /// <summary>
    /// 同步耗时（毫秒）
    /// </summary>
    public long SyncElapsedMilliseconds { get; set; }
}

/// <summary>
/// 任务同步详情
/// </summary>
public class TaskSyncDetail
{
    /// <summary>
    /// 任务ID
    /// </summary>
    public long TaskId { get; set; }

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

    /// <summary>
    /// 同步是否成功
    /// </summary>
    public bool IsSyncSuccessful { get; set; }

    /// <summary>
    /// 原始状态
    /// </summary>
    public string OriginalStatus { get; set; } = string.Empty;

    /// <summary>
    /// 目标状态
    /// </summary>
    public string TargetStatus { get; set; } = string.Empty;

    /// <summary>
    /// 实际状态
    /// </summary>
    public string ActualStatus { get; set; } = string.Empty;

    /// <summary>
    /// 同步错误信息
    /// </summary>
    public string SyncError { get; set; } = string.Empty;

    /// <summary>
    /// 同步时间
    /// </summary>
    public DateTime SyncTime { get; set; }
}

/// <summary>
/// 发布验证结果
/// </summary>
public class PublishValidationResult
{
    /// <summary>
    /// 验证是否通过
    /// </summary>
    public bool IsValid { get; set; }

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

    /// <summary>
    /// 阻塞性错误（会阻止发布）
    /// </summary>
    public List<IntegrationValidationError> BlockingErrors { get; set; } = new();

    /// <summary>
    /// 警告性问题（不阻止发布但需要注意）
    /// </summary>
    public List<ValidationWarning> Warnings { get; set; } = new();

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

/// <summary>
/// 整合通知发送结果
/// </summary>
public class IntegrationNotificationResult
{
    /// <summary>
    /// 通知类型
    /// </summary>
    public string NotificationType { get; set; } = string.Empty;

    /// <summary>
    /// 接收人员ID
    /// </summary>
    public long RecipientId { get; set; }

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

    /// <summary>
    /// 发送是否成功
    /// </summary>
    public bool IsSent { get; set; }

    /// <summary>
    /// 发送时间
    /// </summary>
    public DateTime SentTime { get; set; }

    /// <summary>
    /// 发送失败原因
    /// </summary>
    public string FailureReason { get; set; } = string.Empty;
}

/// <summary>
/// 发布统计信息
/// </summary>
public class PublishStatistics
{
    /// <summary>
    /// 总任务数
    /// </summary>
    public int TotalTaskCount { get; set; }

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

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

    /// <summary>
    /// 涉及人员数量
    /// </summary>
    public int InvolvedPersonnelCount { get; set; }

    /// <summary>
    /// 涉及设备数量
    /// </summary>
    public int InvolvedEquipmentCount { get; set; }

    /// <summary>
    /// 发布成功率
    /// </summary>
    public decimal PublishSuccessRate { get; set; }

    /// <summary>
    /// 发布总耗时（毫秒）
    /// </summary>
    public long TotalElapsedMilliseconds { get; set; }
}