using System;
using System.Collections.Generic;
using System.Linq;
using NPP.SmartSchedue.Api.Contracts.Services.Integration.Input;

namespace NPP.SmartSchedue.Api.Contracts.Services.Integration.Output
{
    /// <summary>
    /// 优化权重配置执行结果
    /// 智能分配系统优化权重应用的完整结果数据模型
    /// 包含权重应用效果、性能分析、业务洞察等全面信息
    /// 深度业务思考：评估权重配置对分配结果的实际影响和优化效果
    /// </summary>
    public class OptimizationWeightsResult
    {
        #region 核心执行结果

        /// <summary>
        /// 权重配置应用是否成功
        /// </summary>
        public bool IsSuccessful { get; set; }

        /// <summary>
        /// 应用的权重配置
        /// 记录实际使用的权重配置详情
        /// </summary>
        public OptimizationWeights AppliedWeights { get; set; } = new();

        /// <summary>
        /// 权重应用前的分配结果摘要
        /// </summary>
        public AllocationResultSummary BeforeWeightApplication { get; set; } = new();

        /// <summary>
        /// 权重应用后的分配结果摘要
        /// </summary>
        public AllocationResultSummary AfterWeightApplication { get; set; } = new();

        /// <summary>
        /// 权重应用改进效果
        /// 量化权重配置带来的实际改进
        /// </summary>
        public WeightApplicationImprovement Improvement { get; set; } = new();

        #endregion

        #region 权重效果分析

        /// <summary>
        /// 各权重维度的实际影响分析
        /// Key: 权重维度名称, Value: 影响分析结果
        /// </summary>
        public Dictionary<string, WeightDimensionImpact> DimensionImpactAnalysis { get; set; } = new();

        /// <summary>
        /// 权重配置有效性评分 (0-100)
        /// 综合评估权重配置的有效性和合理性
        /// </summary>
        public double WeightEffectivenessScore { get; set; }

        /// <summary>
        /// 权重分布均衡性分析
        /// 评估权重配置的分布是否合理均衡
        /// </summary>
        public WeightDistributionAnalysis DistributionAnalysis { get; set; } = new();

        /// <summary>
        /// 权重敏感性分析
        /// 分析各权重变化对结果的敏感程度
        /// </summary>
        public Dictionary<string, double> WeightSensitivityAnalysis { get; set; } = new();

        #endregion

        #region 业务效果评估

        /// <summary>
        /// 业务目标达成情况
        /// 评估权重配置对各业务目标的达成效果
        /// </summary>
        public BusinessObjectiveAchievement ObjectiveAchievement { get; set; } = new();

        /// <summary>
        /// 分配质量提升分析
        /// </summary>
        public AllocationQualityImprovement QualityImprovement { get; set; } = new();

        /// <summary>
        /// 人员满意度影响评估
        /// </summary>
        public PersonnelSatisfactionImpact SatisfactionImpact { get; set; } = new();

        /// <summary>
        /// 运营效率影响分析
        /// </summary>
        public OperationalEfficiencyImpact EfficiencyImpact { get; set; } = new();

        #endregion

        #region 性能和统计数据

        /// <summary>
        /// 权重应用执行时间（毫秒）
        /// </summary>
        public long ExecutionTimeMs { get; set; }

        /// <summary>
        /// 权重计算统计信息
        /// </summary>
        public WeightCalculationStatistics CalculationStatistics { get; set; } = new();

        /// <summary>
        /// 权重应用过程日志
        /// 记录权重应用的详细过程
        /// </summary>
        public List<WeightApplicationLog> ApplicationLogs { get; set; } = new();

        /// <summary>
        /// 性能监控指标
        /// </summary>
        public Dictionary<string, object> PerformanceMetrics { get; set; } = new();

        #endregion

        #region 优化建议和报告

        /// <summary>
        /// 权重优化建议
        /// 基于执行结果提出的权重调整建议
        /// </summary>
        public List<WeightOptimizationSuggestion> OptimizationSuggestions { get; set; } = new();

        /// <summary>
        /// 权重配置评估报告
        /// 人性化的权重应用效果总结
        /// </summary>
        public string EvaluationReport { get; set; } = string.Empty;

        /// <summary>
        /// 下一步行动建议
        /// </summary>
        public List<WeightActionRecommendation> NextStepRecommendations { get; set; } = new();

        /// <summary>
        /// 权重配置风险评估
        /// </summary>
        public WeightConfigurationRisk RiskAssessment { get; set; } = new();

        #endregion

        #region 比较和基准分析

        /// <summary>
        /// 与历史权重配置的比较
        /// </summary>
        public List<HistoricalWeightComparison> HistoricalComparisons { get; set; } = new();

        /// <summary>
        /// 与基准权重配置的比较
        /// </summary>
        public Dictionary<string, BenchmarkComparison> BenchmarkComparisons { get; set; } = new();

        /// <summary>
        /// 权重配置排名
        /// 在所有测试配置中的表现排名
        /// </summary>
        public WeightConfigurationRanking ConfigurationRanking { get; set; } = new();

        #endregion

        #region 辅助分析方法

        /// <summary>
        /// 计算总体改进率
        /// 综合各维度的改进情况
        /// </summary>
        public double CalculateOverallImprovementRate()
        {
            if (BeforeWeightApplication.TotalScore <= 0) return 0;

            var qualityImprovement = (AfterWeightApplication.AverageQualityScore - BeforeWeightApplication.AverageQualityScore) / BeforeWeightApplication.AverageQualityScore;
            var successRateImprovement = (AfterWeightApplication.SuccessRate - BeforeWeightApplication.SuccessRate) / Math.Max(BeforeWeightApplication.SuccessRate, 1);
            var efficiencyImprovement = Improvement.EfficiencyImprovement / 100;

            return Math.Round((qualityImprovement + successRateImprovement + efficiencyImprovement) / 3 * 100, 2);
        }

        /// <summary>
        /// 获取最显著的权重影响因子
        /// </summary>
        public List<WeightImpactFactor> GetTopImpactFactors(int topCount = 5)
        {
            return DimensionImpactAnalysis.Values
                .OrderByDescending(impact => Math.Abs(impact.ImpactScore))
                .Take(topCount)
                .Select(impact => new WeightImpactFactor
                {
                    DimensionName = impact.DimensionName,
                    ImpactScore = impact.ImpactScore,
                    ImpactDescription = impact.ImpactDescription
                })
                .ToList();
        }

        /// <summary>
        /// 评估权重配置的稳定性
        /// </summary>
        public WeightStabilityAssessment AssessConfigurationStability()
        {
            var assessment = new WeightStabilityAssessment();

            // 计算权重标准差
            var weights = AppliedWeights.ToDictionary().Values.ToList();
            var mean = weights.Average();
            var variance = weights.Sum(w => Math.Pow(w - mean, 2)) / weights.Count;
            assessment.WeightVariance = variance;
            assessment.WeightStandardDeviation = Math.Sqrt(variance);

            // 评估敏感性稳定性
            var sensitivities = WeightSensitivityAnalysis.Values.ToList();
            if (sensitivities.Any())
            {
                assessment.SensitivityRange = sensitivities.Max() - sensitivities.Min();
                assessment.AverageSensitivity = sensitivities.Average();
            }

            // 确定稳定性等级
            assessment.StabilityLevel = DetermineStabilityLevel(assessment);

            return assessment;
        }

        /// <summary>
        /// 确定权重配置稳定性等级
        /// </summary>
        private WeightStabilityLevel DetermineStabilityLevel(WeightStabilityAssessment assessment)
        {
            if (assessment.WeightStandardDeviation < 0.1 && assessment.SensitivityRange < 0.2)
                return WeightStabilityLevel.VeryStable;
            
            if (assessment.WeightStandardDeviation < 0.2 && assessment.SensitivityRange < 0.4)
                return WeightStabilityLevel.Stable;
            
            if (assessment.WeightStandardDeviation < 0.3 && assessment.SensitivityRange < 0.6)
                return WeightStabilityLevel.ModeratelyStable;
            
            if (assessment.WeightStandardDeviation < 0.4 && assessment.SensitivityRange < 0.8)
                return WeightStabilityLevel.Unstable;
            
            return WeightStabilityLevel.VeryUnstable;
        }

        /// <summary>
        /// 生成权重配置摘要
        /// </summary>
        public WeightResultSummary GenerateSummary()
        {
            return new WeightResultSummary
            {
                IsSuccessful = IsSuccessful,
                ConfigurationName = AppliedWeights.ConfigurationName,
                OverallImprovementRate = CalculateOverallImprovementRate(),
                WeightEffectivenessScore = WeightEffectivenessScore,
                TopImpactFactors = GetTopImpactFactors(3),
                StabilityAssessment = AssessConfigurationStability(),
                ExecutionTimeMs = ExecutionTimeMs,
                RecommendationCount = OptimizationSuggestions.Count,
                RiskLevel = RiskAssessment.OverallRiskLevel
            };
        }

        #endregion
    }

    #region 支持类定义

    /// <summary>
    /// 分配结果摘要
    /// </summary>
    public class AllocationResultSummary
    {
        /// <summary>
        /// 总任务数
        /// </summary>
        public int TotalTasks { get; set; }

        /// <summary>
        /// 成功分配数
        /// </summary>
        public int SuccessfulAllocations { get; set; }

        /// <summary>
        /// 成功率 (0-100)
        /// </summary>
        public double SuccessRate => TotalTasks > 0 ? (double)SuccessfulAllocations / TotalTasks * 100 : 0;

        /// <summary>
        /// 平均质量评分
        /// </summary>
        public double AverageQualityScore { get; set; }

        /// <summary>
        /// 总评分
        /// </summary>
        public double TotalScore { get; set; }

        /// <summary>
        /// 公平性评分
        /// </summary>
        public double FairnessScore { get; set; }

        /// <summary>
        /// 生成时间
        /// </summary>
        public DateTime GeneratedTime { get; set; } = DateTime.Now;
    }

    /// <summary>
    /// 权重应用改进效果
    /// </summary>
    public class WeightApplicationImprovement
    {
        /// <summary>
        /// 质量改进百分比
        /// </summary>
        public double QualityImprovement { get; set; }

        /// <summary>
        /// 成功率改进百分比
        /// </summary>
        public double SuccessRateImprovement { get; set; }

        /// <summary>
        /// 效率改进百分比
        /// </summary>
        public double EfficiencyImprovement { get; set; }

        /// <summary>
        /// 公平性改进百分比
        /// </summary>
        public double FairnessImprovement { get; set; }

        /// <summary>
        /// 综合改进评分 (0-100)
        /// </summary>
        public double OverallImprovementScore => (QualityImprovement + SuccessRateImprovement + EfficiencyImprovement + FairnessImprovement) / 4;

        /// <summary>
        /// 改进详细描述
        /// </summary>
        public string ImprovementDescription { get; set; } = string.Empty;
    }

    /// <summary>
    /// 权重维度影响分析
    /// </summary>
    public class WeightDimensionImpact
    {
        /// <summary>
        /// 权重维度名称
        /// </summary>
        public string DimensionName { get; set; } = string.Empty;

        /// <summary>
        /// 权重值
        /// </summary>
        public double WeightValue { get; set; }

        /// <summary>
        /// 影响评分 (-100 到 100)
        /// 正值表示正面影响，负值表示负面影响
        /// </summary>
        public double ImpactScore { get; set; }

        /// <summary>
        /// 影响描述
        /// </summary>
        public string ImpactDescription { get; set; } = string.Empty;

        /// <summary>
        /// 实际应用次数
        /// 该权重维度在分配过程中被实际使用的次数
        /// </summary>
        public int ApplicationCount { get; set; }

        /// <summary>
        /// 平均贡献度
        /// 该权重维度对最终分配结果的平均贡献度
        /// </summary>
        public double AverageContribution { get; set; }

        /// <summary>
        /// 标准差
        /// 该权重维度贡献度的稳定性指标
        /// </summary>
        public double StandardDeviation { get; set; }
    }

    /// <summary>
    /// 权重分布均衡性分析
    /// </summary>
    public class WeightDistributionAnalysis
    {
        /// <summary>
        /// 权重分布方差
        /// </summary>
        public double DistributionVariance { get; set; }

        /// <summary>
        /// 权重分布标准差
        /// </summary>
        public double DistributionStandardDeviation { get; set; }

        /// <summary>
        /// 最大权重值
        /// </summary>
        public double MaxWeight { get; set; }

        /// <summary>
        /// 最小权重值
        /// </summary>
        public double MinWeight { get; set; }

        /// <summary>
        /// 权重范围
        /// </summary>
        public double WeightRange => MaxWeight - MinWeight;

        /// <summary>
        /// 权重集中度
        /// 衡量权重是否过于集中在某几个维度
        /// </summary>
        public double ConcentrationIndex { get; set; }

        /// <summary>
        /// 分布均衡性评级
        /// </summary>
        public DistributionBalance BalanceRating { get; set; } = DistributionBalance.Moderate;
    }

    /// <summary>
    /// 业务目标达成情况
    /// </summary>
    public class BusinessObjectiveAchievement
    {
        /// <summary>
        /// 效率目标达成率 (0-100)
        /// </summary>
        public double EfficiencyAchievementRate { get; set; }

        /// <summary>
        /// 公平性目标达成率 (0-100)
        /// </summary>
        public double FairnessAchievementRate { get; set; }

        /// <summary>
        /// 质量目标达成率 (0-100)
        /// </summary>
        public double QualityAchievementRate { get; set; }

        /// <summary>
        /// 连续性目标达成率 (0-100)
        /// </summary>
        public double ContinuityAchievementRate { get; set; }

        /// <summary>
        /// 成本控制目标达成率 (0-100)
        /// </summary>
        public double CostControlAchievementRate { get; set; }

        /// <summary>
        /// 整体目标达成率 (0-100)
        /// </summary>
        public double OverallAchievementRate => (EfficiencyAchievementRate + FairnessAchievementRate + 
            QualityAchievementRate + ContinuityAchievementRate + CostControlAchievementRate) / 5;

        /// <summary>
        /// 目标达成详情
        /// </summary>
        public List<ObjectiveAchievementDetail> AchievementDetails { get; set; } = new();
    }

    /// <summary>
    /// 目标达成详情
    /// </summary>
    public class ObjectiveAchievementDetail
    {
        /// <summary>
        /// 目标名称
        /// </summary>
        public string ObjectiveName { get; set; } = string.Empty;

        /// <summary>
        /// 目标值
        /// </summary>
        public double TargetValue { get; set; }

        /// <summary>
        /// 实际值
        /// </summary>
        public double ActualValue { get; set; }

        /// <summary>
        /// 达成率 (0-100)
        /// </summary>
        public double AchievementRate => TargetValue > 0 ? Math.Min(100, ActualValue / TargetValue * 100) : 0;

        /// <summary>
        /// 达成状态
        /// </summary>
        public AchievementStatus Status { get; set; } = AchievementStatus.InProgress;
    }

    /// <summary>
    /// 分配质量提升分析
    /// </summary>
    public class AllocationQualityImprovement
    {
        /// <summary>
        /// 匹配度提升
        /// </summary>
        public double MatchingImprovement { get; set; }

        /// <summary>
        /// 约束符合度提升
        /// </summary>
        public double ConstraintComplianceImprovement { get; set; }

        /// <summary>
        /// 风险降低程度
        /// </summary>
        public double RiskReduction { get; set; }

        /// <summary>
        /// 稳定性提升
        /// </summary>
        public double StabilityImprovement { get; set; }

        /// <summary>
        /// 质量提升详细报告
        /// </summary>
        public string QualityImprovementReport { get; set; } = string.Empty;
    }

    /// <summary>
    /// 人员满意度影响评估
    /// </summary>
    public class PersonnelSatisfactionImpact
    {
        /// <summary>
        /// 工作负载满意度变化
        /// </summary>
        public double WorkloadSatisfactionChange { get; set; }

        /// <summary>
        /// 班次安排满意度变化
        /// </summary>
        public double ShiftSatisfactionChange { get; set; }

        /// <summary>
        /// 技能匹配满意度变化
        /// </summary>
        public double SkillMatchSatisfactionChange { get; set; }

        /// <summary>
        /// 整体满意度变化
        /// </summary>
        public double OverallSatisfactionChange => (WorkloadSatisfactionChange + ShiftSatisfactionChange + SkillMatchSatisfactionChange) / 3;

        /// <summary>
        /// 满意度影响详情
        /// </summary>
        public List<SatisfactionImpactDetail> ImpactDetails { get; set; } = new();
    }

    /// <summary>
    /// 满意度影响详情
    /// </summary>
    public class SatisfactionImpactDetail
    {
        /// <summary>
        /// 人员ID
        /// </summary>
        public long PersonnelId { get; set; }

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

        /// <summary>
        /// 满意度变化分数
        /// </summary>
        public double SatisfactionChange { get; set; }

        /// <summary>
        /// 变化原因
        /// </summary>
        public string ChangeReason { get; set; } = string.Empty;
    }

    /// <summary>
    /// 运营效率影响分析
    /// </summary>
    public class OperationalEfficiencyImpact
    {
        /// <summary>
        /// 分配效率提升 (%)
        /// </summary>
        public double AllocationEfficiencyImprovement { get; set; }

        /// <summary>
        /// 执行时间减少 (%)
        /// </summary>
        public double ExecutionTimeReduction { get; set; }

        /// <summary>
        /// 资源利用率提升 (%)
        /// </summary>
        public double ResourceUtilizationImprovement { get; set; }

        /// <summary>
        /// 整体运营效率改进 (%)
        /// </summary>
        public double OverallEfficiencyImprovement => (AllocationEfficiencyImprovement + ExecutionTimeReduction + ResourceUtilizationImprovement) / 3;

        /// <summary>
        /// 效率影响报告
        /// </summary>
        public string EfficiencyImpactReport { get; set; } = string.Empty;
    }

    /// <summary>
    /// 权重计算统计信息
    /// </summary>
    public class WeightCalculationStatistics
    {
        /// <summary>
        /// 总计算次数
        /// </summary>
        public int TotalCalculations { get; set; }

        /// <summary>
        /// 平均计算时间（毫秒）
        /// </summary>
        public double AverageCalculationTimeMs { get; set; }

        /// <summary>
        /// 权重应用成功次数
        /// </summary>
        public int SuccessfulApplications { get; set; }

        /// <summary>
        /// 权重应用失败次数
        /// </summary>
        public int FailedApplications { get; set; }

        /// <summary>
        /// 应用成功率 (0-100)
        /// </summary>
        public double ApplicationSuccessRate => TotalCalculations > 0 ? (double)SuccessfulApplications / TotalCalculations * 100 : 0;

        /// <summary>
        /// 缓存命中次数
        /// </summary>
        public int CacheHits { get; set; }

        /// <summary>
        /// 缓存未命中次数
        /// </summary>
        public int CacheMisses { get; set; }

        /// <summary>
        /// 缓存命中率 (0-100)
        /// </summary>
        public double CacheHitRate => (CacheHits + CacheMisses) > 0 ? (double)CacheHits / (CacheHits + CacheMisses) * 100 : 0;
    }

    /// <summary>
    /// 权重应用日志
    /// </summary>
    public class WeightApplicationLog
    {
        /// <summary>
        /// 日志时间
        /// </summary>
        public DateTime LogTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 日志级别
        /// </summary>
        public LogLevel Level { get; set; } = LogLevel.Info;

        /// <summary>
        /// 日志消息
        /// </summary>
        public string Message { get; set; } = string.Empty;

        /// <summary>
        /// 相关的权重维度
        /// </summary>
        public string WeightDimension { get; set; } = string.Empty;

        /// <summary>
        /// 详细数据
        /// </summary>
        public Dictionary<string, object> Details { get; set; } = new();
    }

    /// <summary>
    /// 权重优化建议
    /// </summary>
    public class WeightOptimizationSuggestion
    {
        /// <summary>
        /// 建议ID
        /// </summary>
        public string SuggestionId { get; set; } = Guid.NewGuid().ToString();

        /// <summary>
        /// 建议类型
        /// </summary>
        public OptimizationSuggestionType Type { get; set; } = OptimizationSuggestionType.WeightAdjustment;

        /// <summary>
        /// 建议标题
        /// </summary>
        public string Title { get; set; } = string.Empty;

        /// <summary>
        /// 建议描述
        /// </summary>
        public string Description { get; set; } = string.Empty;

        /// <summary>
        /// 目标权重维度
        /// </summary>
        public string TargetDimension { get; set; } = string.Empty;

        /// <summary>
        /// 当前值
        /// </summary>
        public double CurrentValue { get; set; }

        /// <summary>
        /// 建议值
        /// </summary>
        public double SuggestedValue { get; set; }

        /// <summary>
        /// 预期改进效果
        /// </summary>
        public double ExpectedImprovement { get; set; }

        /// <summary>
        /// 优先级 (1-10)
        /// </summary>
        public int Priority { get; set; } = 5;

        /// <summary>
        /// 置信度 (0-100)
        /// </summary>
        public double Confidence { get; set; } = 80;

        /// <summary>
        /// 建议理由
        /// </summary>
        public string Rationale { get; set; } = string.Empty;
    }

    /// <summary>
    /// 权重行动建议
    /// </summary>
    public class WeightActionRecommendation
    {
        /// <summary>
        /// 行动类型
        /// </summary>
        public WeightActionType ActionType { get; set; } = WeightActionType.Monitor;

        /// <summary>
        /// 行动描述
        /// </summary>
        public string ActionDescription { get; set; } = string.Empty;

        /// <summary>
        /// 建议执行时间
        /// </summary>
        public DateTime RecommendedExecutionTime { get; set; }

        /// <summary>
        /// 紧急程度 (1-10)
        /// </summary>
        public int UrgencyLevel { get; set; } = 5;

        /// <summary>
        /// 负责角色
        /// </summary>
        public string ResponsibleRole { get; set; } = string.Empty;

        /// <summary>
        /// 预期结果
        /// </summary>
        public string ExpectedOutcome { get; set; } = string.Empty;
    }

    /// <summary>
    /// 权重配置风险评估
    /// </summary>
    public class WeightConfigurationRisk
    {
        /// <summary>
        /// 整体风险等级
        /// </summary>
        public RiskLevel OverallRiskLevel { get; set; } = RiskLevel.Low;

        /// <summary>
        /// 风险因子列表
        /// </summary>
        public List<WeightRiskFactor> RiskFactors { get; set; } = new();

        /// <summary>
        /// 风险评分 (0-100)
        /// </summary>
        public double RiskScore { get; set; }

        /// <summary>
        /// 风险描述
        /// </summary>
        public string RiskDescription { get; set; } = string.Empty;

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

    /// <summary>
    /// 权重风险因子
    /// </summary>
    public class WeightRiskFactor
    {
        /// <summary>
        /// 风险类型
        /// </summary>
        public string RiskType { get; set; } = string.Empty;

        /// <summary>
        /// 风险描述
        /// </summary>
        public string Description { get; set; } = string.Empty;

        /// <summary>
        /// 风险等级
        /// </summary>
        public RiskLevel Level { get; set; } = RiskLevel.Low;

        /// <summary>
        /// 风险概率 (0-100)
        /// </summary>
        public double Probability { get; set; }

        /// <summary>
        /// 风险影响 (0-100)
        /// </summary>
        public double Impact { get; set; }
    }

    /// <summary>
    /// 历史权重配置比较
    /// </summary>
    public class HistoricalWeightComparison
    {
        /// <summary>
        /// 比较日期
        /// </summary>
        public DateTime ComparisonDate { get; set; }

        /// <summary>
        /// 历史配置名称
        /// </summary>
        public string HistoricalConfigurationName { get; set; } = string.Empty;

        /// <summary>
        /// 性能改进 (%)
        /// </summary>
        public double PerformanceImprovement { get; set; }

        /// <summary>
        /// 质量改进 (%)
        /// </summary>
        public double QualityImprovement { get; set; }

        /// <summary>
        /// 比较摘要
        /// </summary>
        public string ComparisonSummary { get; set; } = string.Empty;
    }

    /// <summary>
    /// 基准比较
    /// </summary>
    public class BenchmarkComparison
    {
        /// <summary>
        /// 基准名称
        /// </summary>
        public string BenchmarkName { get; set; } = string.Empty;

        /// <summary>
        /// 相对表现 (%)
        /// </summary>
        public double RelativePerformance { get; set; }

        /// <summary>
        /// 比较维度
        /// </summary>
        public Dictionary<string, double> ComparisonDimensions { get; set; } = new();

        /// <summary>
        /// 比较结果
        /// </summary>
        public ComparisonResult Result { get; set; } = ComparisonResult.Equal;
    }

    /// <summary>
    /// 权重配置排名
    /// </summary>
    public class WeightConfigurationRanking
    {
        /// <summary>
        /// 整体排名
        /// </summary>
        public int OverallRank { get; set; }

        /// <summary>
        /// 总配置数量
        /// </summary>
        public int TotalConfigurations { get; set; }

        /// <summary>
        /// 百分位排名
        /// </summary>
        public double PercentileRank => TotalConfigurations > 0 ? (double)(TotalConfigurations - OverallRank + 1) / TotalConfigurations * 100 : 0;

        /// <summary>
        /// 各维度排名
        /// </summary>
        public Dictionary<string, int> DimensionRankings { get; set; } = new();

        /// <summary>
        /// 排名变化趋势
        /// </summary>
        public RankingTrend Trend { get; set; } = RankingTrend.Stable;
    }

    /// <summary>
    /// 权重影响因子
    /// </summary>
    public class WeightImpactFactor
    {
        /// <summary>
        /// 维度名称
        /// </summary>
        public string DimensionName { get; set; } = string.Empty;

        /// <summary>
        /// 影响评分
        /// </summary>
        public double ImpactScore { get; set; }

        /// <summary>
        /// 影响描述
        /// </summary>
        public string ImpactDescription { get; set; } = string.Empty;
    }

    /// <summary>
    /// 权重稳定性评估
    /// </summary>
    public class WeightStabilityAssessment
    {
        /// <summary>
        /// 权重方差
        /// </summary>
        public double WeightVariance { get; set; }

        /// <summary>
        /// 权重标准差
        /// </summary>
        public double WeightStandardDeviation { get; set; }

        /// <summary>
        /// 敏感性范围
        /// </summary>
        public double SensitivityRange { get; set; }

        /// <summary>
        /// 平均敏感性
        /// </summary>
        public double AverageSensitivity { get; set; }

        /// <summary>
        /// 稳定性等级
        /// </summary>
        public WeightStabilityLevel StabilityLevel { get; set; } = WeightStabilityLevel.Stable;
    }

    /// <summary>
    /// 权重结果摘要
    /// </summary>
    public class WeightResultSummary
    {
        /// <summary>
        /// 执行是否成功
        /// </summary>
        public bool IsSuccessful { get; set; }

        /// <summary>
        /// 配置名称
        /// </summary>
        public string ConfigurationName { get; set; } = string.Empty;

        /// <summary>
        /// 整体改进率 (%)
        /// </summary>
        public double OverallImprovementRate { get; set; }

        /// <summary>
        /// 权重有效性评分
        /// </summary>
        public double WeightEffectivenessScore { get; set; }

        /// <summary>
        /// 主要影响因子
        /// </summary>
        public List<WeightImpactFactor> TopImpactFactors { get; set; } = new();

        /// <summary>
        /// 稳定性评估
        /// </summary>
        public WeightStabilityAssessment StabilityAssessment { get; set; } = new();

        /// <summary>
        /// 执行时间（毫秒）
        /// </summary>
        public long ExecutionTimeMs { get; set; }

        /// <summary>
        /// 建议数量
        /// </summary>
        public int RecommendationCount { get; set; }

        /// <summary>
        /// 风险等级
        /// </summary>
        public RiskLevel RiskLevel { get; set; } = RiskLevel.Low;
    }

    #endregion

    #region 枚举定义

    /// <summary>
    /// 分布均衡性枚举
    /// </summary>
    public enum DistributionBalance
    {
        /// <summary>
        /// 非常不均衡
        /// </summary>
        VeryUnbalanced = 1,

        /// <summary>
        /// 不均衡
        /// </summary>
        Unbalanced = 2,

        /// <summary>
        /// 适中
        /// </summary>
        Moderate = 3,

        /// <summary>
        /// 均衡
        /// </summary>
        Balanced = 4,

        /// <summary>
        /// 非常均衡
        /// </summary>
        VeryBalanced = 5
    }

    /// <summary>
    /// 达成状态枚举
    /// </summary>
    public enum AchievementStatus
    {
        /// <summary>
        /// 未开始
        /// </summary>
        NotStarted = 0,

        /// <summary>
        /// 进行中
        /// </summary>
        InProgress = 1,

        /// <summary>
        /// 已达成
        /// </summary>
        Achieved = 2,

        /// <summary>
        /// 超额达成
        /// </summary>
        Exceeded = 3,

        /// <summary>
        /// 未达成
        /// </summary>
        Failed = 4
    }

    /// <summary>
    /// 日志级别枚举
    /// </summary>
    public enum LogLevel
    {
        /// <summary>
        /// 调试
        /// </summary>
        Debug = 0,

        /// <summary>
        /// 信息
        /// </summary>
        Info = 1,

        /// <summary>
        /// 警告
        /// </summary>
        Warning = 2,

        /// <summary>
        /// 错误
        /// </summary>
        Error = 3,

        /// <summary>
        /// 严重错误
        /// </summary>
        Critical = 4
    }

    /// <summary>
    /// 优化建议类型枚举
    /// </summary>
    public enum OptimizationSuggestionType
    {
        /// <summary>
        /// 权重调整
        /// </summary>
        WeightAdjustment = 1,

        /// <summary>
        /// 策略变更
        /// </summary>
        StrategyChange = 2,

        /// <summary>
        /// 配置优化
        /// </summary>
        ConfigurationOptimization = 3,

        /// <summary>
        /// 规则调整
        /// </summary>
        RuleAdjustment = 4,

        /// <summary>
        /// 性能优化
        /// </summary>
        PerformanceOptimization = 5
    }

    /// <summary>
    /// 权重行动类型枚举
    /// </summary>
    public enum WeightActionType
    {
        /// <summary>
        /// 立即调整
        /// </summary>
        ImmediateAdjustment = 1,

        /// <summary>
        /// 监控观察
        /// </summary>
        Monitor = 2,

        /// <summary>
        /// 详细分析
        /// </summary>
        DetailedAnalysis = 3,

        /// <summary>
        /// 配置备份
        /// </summary>
        ConfigurationBackup = 4,

        /// <summary>
        /// 回滚配置
        /// </summary>
        ConfigurationRollback = 5
    }


    /// <summary>
    /// 比较结果枚举
    /// </summary>
    public enum ComparisonResult
    {
        /// <summary>
        /// 明显更差
        /// </summary>
        MuchWorse = -2,

        /// <summary>
        /// 更差
        /// </summary>
        Worse = -1,

        /// <summary>
        /// 相等
        /// </summary>
        Equal = 0,

        /// <summary>
        /// 更好
        /// </summary>
        Better = 1,

        /// <summary>
        /// 明显更好
        /// </summary>
        MuchBetter = 2
    }

    /// <summary>
    /// 排名趋势枚举
    /// </summary>
    public enum RankingTrend
    {
        /// <summary>
        /// 下降
        /// </summary>
        Declining = -1,

        /// <summary>
        /// 稳定
        /// </summary>
        Stable = 0,

        /// <summary>
        /// 上升
        /// </summary>
        Rising = 1
    }

    /// <summary>
    /// 权重稳定性等级枚举
    /// </summary>
    public enum WeightStabilityLevel
    {
        /// <summary>
        /// 非常不稳定
        /// </summary>
        VeryUnstable = 1,

        /// <summary>
        /// 不稳定
        /// </summary>
        Unstable = 2,

        /// <summary>
        /// 中等稳定
        /// </summary>
        ModeratelyStable = 3,

        /// <summary>
        /// 稳定
        /// </summary>
        Stable = 4,

        /// <summary>
        /// 非常稳定
        /// </summary>
        VeryStable = 5
    }

    #endregion
}