using System;

namespace MultiWheelC.TrajectoryPlanning.CoarsePath;

/// <summary>一次规划的只读统计与终止说明；长度和净空单位为 m。</summary>
public sealed class PlanningDiagnostics
{
    /// <summary>
    /// 创建规划统计快照。
    /// 参数中的节点数量均为非负计数；pathLengthMeters 和 minimumBodyClearanceMeters 单位为 m；elapsed 为总耗时；pathSearchElapsed 为地图和起终点预检通过后的路径产出耗时；terminationReason 为可读终止说明，可为 null。
    /// </summary>
    public PlanningDiagnostics(
        int expandedNodeCount = 0,
        int generatedNodeCount = 0,
        int reopenedNodeCount = 0,
        int staleOpenListEntryCount = 0,
        int peakOpenListCount = 0,
        double pathLengthMeters = 0d,
        double minimumBodyClearanceMeters = 0d,
        TimeSpan elapsed = default(TimeSpan),
        string terminationReason = null,
        TimeSpan pathSearchElapsed = default(TimeSpan))
    {
        ExpandedNodeCount = expandedNodeCount;
        GeneratedNodeCount = generatedNodeCount;
        ReopenedNodeCount = reopenedNodeCount;
        StaleOpenListEntryCount = staleOpenListEntryCount;
        PeakOpenListCount = peakOpenListCount;
        PathLengthMeters = pathLengthMeters;
        MinimumBodyClearanceMeters = minimumBodyClearanceMeters;
        Elapsed = elapsed;
        PathSearchElapsed = pathSearchElapsed;
        TerminationReason = terminationReason ?? string.Empty;
    }

    /// <summary>从 Open List 取出并真正扩展的节点数量。</summary>
    public int ExpandedNodeCount { get; }

    /// <summary>生成并尝试加入搜索状态的节点数量。</summary>
    public int GeneratedNodeCount { get; }

    /// <summary>以严格更小代价到达同一离散键而重新打开的节点数量。</summary>
    public int ReopenedNodeCount { get; }

    /// <summary>从 Open List 取出后因已有更优条目而丢弃的陈旧堆条目数量。</summary>
    public int StaleOpenListEntryCount { get; }

    /// <summary>搜索期间 Open List 同时容纳的最大有效或待丢弃条目数量。</summary>
    public int PeakOpenListCount { get; }

    /// <summary>成功路径的累计弧长，单位 m；失败结果通常为 0。</summary>
    public double PathLengthMeters { get; }

    /// <summary>成功路径所有点中车体保守净空下界的最小值，单位 m；失败结果通常为 0。</summary>
    public double MinimumBodyClearanceMeters { get; }

    /// <summary>从规划入口到返回结果的总耗时。</summary>
    public TimeSpan Elapsed { get; }

    /// <summary>地图和起终点预检通过后，二维启发式、Hybrid A*、回溯、装配和最终复核的耗时；不含建图，搜索前失败时为零。</summary>
    public TimeSpan PathSearchElapsed { get; }

    /// <summary>面向调用方的终止原因；成功时可为空字符串。</summary>
    public string TerminationReason { get; }
}
