using System;
using System.Collections.Generic;

namespace NPP.SmartSchedue.Api.Contracts.Services.Integration.Output
{
    /// <summary>
    /// 任务变更分析结果
    /// 包含变更检测、影响评估和处理建议
    /// </summary>
    public class TaskChangeAnalysisResult
    {
        /// <summary>
        /// 分析ID
        /// </summary>
        public string AnalysisId { get; set; } = Guid.NewGuid().ToString();

        /// <summary>
        /// 任务ID
        /// </summary>
        public long TaskId { get; set; }

        /// <summary>
        /// 变更类型
        /// </summary>
        public TaskChangeTypeEnum ChangeType { get; set; }

        /// <summary>
        /// 变更影响级别
        /// </summary>
        public TaskChangeImpactLevel ImpactLevel { get; set; }

        /// <summary>
        /// 变更详情描述
        /// </summary>
        public string ChangeDescription { get; set; }

        /// <summary>
        /// 影响评估
        /// </summary>
        public ChangeImpactAssessment ImpactAssessment { get; set; } = new();

        /// <summary>
        /// 当前任务状态分析
        /// </summary>
        public CurrentTaskStateAnalysis CurrentStateAnalysis { get; set; } = new();

        /// <summary>
        /// 建议的处理方案
        /// </summary>
        public List<string> RecommendedActions { get; set; } = new();

        /// <summary>
        /// 分析时间
        /// </summary>
        public DateTime AnalysisTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 分析深度
        /// </summary>
        public TaskChangeAnalysisDepth AnalysisDepth { get; set; }

        /// <summary>
        /// 是否需要人工干预
        /// </summary>
        public bool RequiresManualIntervention { get; set; }

        /// <summary>
        /// 预计处理时长（分钟）
        /// </summary>
        public int EstimatedProcessingTimeMinutes { get; set; }

        /// <summary>
        /// 检测到的详细变更列表
        /// </summary>
        public List<DetailedTaskChange> DetectedChanges { get; set; } = new();
    }

    /// <summary>
    /// 任务变更分析深度枚举
    /// </summary>
    public enum TaskChangeAnalysisDepth
    {
        /// <summary>
        /// 基础分析 - 只检查直接影响
        /// </summary>
        Basic = 1,

        /// <summary>
        /// 标准分析 - 包含关联任务检查
        /// </summary>
        Standard = 2,

        /// <summary>
        /// 详细分析 - 包含详细的变更信息
        /// </summary>
        Detailed = 3,

        /// <summary>
        /// 深度分析 - 包含全面的影响评估
        /// </summary>
        Deep = 4,

        /// <summary>
        /// 全量分析 - 最全面的分析，包含性能优化建议
        /// </summary>
        Comprehensive = 5
    }

    /// <summary>
    /// 任务变更影响级别枚举
    /// </summary>
    public enum TaskChangeImpactLevel
    {
        /// <summary>
        /// 无影响
        /// </summary>
        None = 0,

        /// <summary>
        /// 低影响 - 轻微影响，对现有安排影响很小
        /// </summary>
        Low = 1,

        /// <summary>
        /// 轻微影响 - 对现有安排影响很小
        /// </summary>
        Minor = 1,

        /// <summary>
        /// 中等影响 - 需要局部调整
        /// </summary>
        Medium = 2,

        /// <summary>
        /// 中等影响 - 需要局部调整
        /// </summary>
        Moderate = 2,

        /// <summary>
        /// 高影响 - 需要大范围调整
        /// </summary>
        High = 3,

        /// <summary>
        /// 重大影响 - 需要大范围调整
        /// </summary>
        Major = 3,

        /// <summary>
        /// 严重影响 - 需要重新规划
        /// </summary>
        Critical = 4
    }

    /// <summary>
    /// 变更影响评估
    /// </summary>
    public class ChangeImpactAssessment
    {
        /// <summary>
        /// 受影响的任务数量
        /// </summary>
        public int AffectedTaskCount { get; set; }

        /// <summary>
        /// 受影响的人员数量
        /// </summary>
        public int AffectedPersonnelCount { get; set; }

        /// <summary>
        /// 受影响的设备数量
        /// </summary>
        public int AffectedEquipmentCount { get; set; }

        /// <summary>
        /// 时间窗口冲突数量
        /// </summary>
        public int TimeConflictCount { get; set; }

        /// <summary>
        /// 资源冲突数量
        /// </summary>
        public int ResourceConflictCount { get; set; }

        /// <summary>
        /// 预计影响时长（小时）
        /// </summary>
        public decimal EstimatedImpactHours { get; set; }

        /// <summary>
        /// 详细影响说明
        /// </summary>
        public List<string> DetailedImpactDescriptions { get; set; } = new();
    }

    /// <summary>
    /// 当前任务状态分析
    /// </summary>
    public class CurrentTaskStateAnalysis
    {
        /// <summary>
        /// 任务当前状态
        /// </summary>
        public string CurrentStatus { get; set; }

        /// <summary>
        /// 完成百分比
        /// </summary>
        public decimal CompletionPercentage { get; set; }

        /// <summary>
        /// 剩余工作量（小时）
        /// </summary>
        public decimal RemainingWorkHours { get; set; }

        /// <summary>
        /// 当前分配的人员
        /// </summary>
        public List<string> AssignedPersonnel { get; set; } = new();

        /// <summary>
        /// 当前使用的设备
        /// </summary>
        public List<string> AssignedEquipment { get; set; } = new();

        /// <summary>
        /// 是否处于关键路径
        /// </summary>
        public bool IsOnCriticalPath { get; set; }

        /// <summary>
        /// 状态分析备注
        /// </summary>
        public string AnalysisNotes { get; set; }

        /// <summary>
        /// 是否可重新分配
        /// </summary>
        public bool CanReallocate { get; set; } = true;

        /// <summary>
        /// 阻塞原因
        /// </summary>
        public string BlockingReason { get; set; } = string.Empty;

        /// <summary>
        /// 阻塞任务ID列表
        /// </summary>
        public List<long> BlockingTaskIds { get; set; } = new();

        /// <summary>
        /// 已分析的任务列表
        /// </summary>
        public List<long> AnalyzedTasks { get; set; } = new();
    }
}