using System;

namespace MultiWheelC.TrajectoryPlanning.PathSmoothing;

/// <summary>一次平滑尝试的不可变诊断信息。</summary>
public sealed class PathSmoothingDiagnostics
{
    /// <summary>创建不含路径指标的默认诊断信息。</summary>
    public PathSmoothingDiagnostics()
        : this(new PathQualityMetrics(), TimeSpan.Zero, 0, 0d, string.Empty)
    {
    }

    /// <summary>创建完整的平滑诊断快照。</summary>
    public PathSmoothingDiagnostics(
        PathQualityMetrics metrics,
        TimeSpan elapsed,
        int retryCount,
        double acceptedStrength,
        string terminationReason = null)
    {
        Metrics = metrics ?? new PathQualityMetrics();
        Elapsed = elapsed;
        RetryCount = retryCount;
        AcceptedStrength = acceptedStrength;
        TerminationReason = terminationReason ?? string.Empty;
    }

    /// <summary>使用所有测量量创建平滑诊断快照。</summary>
    public PathSmoothingDiagnostics(
        bool isFeasible,
        double pathLengthMeters,
        double maximumAbsoluteVehicleCurvaturePerMeter,
        double rootMeanSquareVehicleCurvaturePerMeter,
        double totalAbsoluteCurvatureVariationPerMeter,
        double curvatureVariationEnergy,
        double minimumBodyClearanceMeters,
        double lengthChangePercent,
        double peakCurvatureChangePercent,
        double curvatureVariationChangePercent,
        double minimumClearanceChangeMeters,
        TimeSpan elapsed,
        int retryCount,
        double acceptedStrength,
        string terminationReason = null)
        : this(
            new PathQualityMetrics(
                isFeasible,
                pathLengthMeters,
                maximumAbsoluteVehicleCurvaturePerMeter,
                rootMeanSquareVehicleCurvaturePerMeter,
                totalAbsoluteCurvatureVariationPerMeter,
                curvatureVariationEnergy,
                minimumBodyClearanceMeters,
                lengthChangePercent,
                peakCurvatureChangePercent,
                curvatureVariationChangePercent,
                minimumClearanceChangeMeters),
            elapsed,
            retryCount,
            acceptedStrength,
            terminationReason)
    {
    }

    /// <summary>路径质量指标；始终非空。</summary>
    public PathQualityMetrics Metrics { get; }

    /// <summary>从算法入口到返回诊断的耗时。</summary>
    public TimeSpan Elapsed { get; }

    /// <summary>已执行的安全强度重试次数。</summary>
    public int RetryCount { get; }

    /// <summary>通过复核的平滑强度；未接受候选时为零。</summary>
    public double AcceptedStrength { get; }

    /// <summary>面向调用方的稳定终止说明。</summary>
    public string TerminationReason { get; }
}
