using System;

namespace MultiWheelC.TrajectoryPlanning.CoarsePath;

/// <summary>
/// Hybrid A* 粗路径搜索的可调配置。
/// 长度和距离使用 m，航向使用 rad，曲率使用 1/m；各项有效范围由规划器在执行前校验。
/// </summary>
public sealed class HybridAStarConfiguration
{
    /// <summary>创建采用 P0 固定安全边界和代价权重的默认配置。</summary>
    public HybridAStarConfiguration()
    {
        PrimitiveLengthMeters = 0.50d;
        IntegrationStepMeters = 0.05d;
        MaximumCollisionCheckStepMeters = 0.025d;
        HeadingResolutionRadians = Math.PI / 36d;
        CurvatureLevelCount = 5;
        GoalPositionToleranceMeters = 0.15d;
        GoalHeadingToleranceRadians = Math.PI / 36d;
        MaximumExpandedNodes = 200000;
        SearchTimeout = TimeSpan.FromSeconds(5d);
        HeuristicWeight = 1d;
        ReverseCostMultiplier = 1.5d;
        GearSwitchPenaltyMeters = 1d;
        CurvatureMagnitudeWeight = 0.10d;
        CurvatureChangePenaltyMetersPerLevel = 0.05d;
        ClearanceCostWeight = 0.20d;
        ClearanceCostDistanceMeters = 0.50d;
        AllowReverse = true;
    }

    /// <summary>单个恒曲率原语的最大行驶长度，单位 m。</summary>
    public double PrimitiveLengthMeters { get; set; }

    /// <summary>原语内部输出积分点之间允许的最大弧长，单位 m。</summary>
    public double IntegrationStepMeters { get; set; }

    /// <summary>连续碰撞检查允许的最大车辆中心位移，单位 m；实际值还受地图分辨率限制。</summary>
    public double MaximumCollisionCheckStepMeters { get; set; }

    /// <summary>搜索状态离散所使用的航向格宽，单位 rad。</summary>
    public double HeadingResolutionRadians { get; set; }

    /// <summary>从最大负曲率到最大正曲率的离散曲率等级数。</summary>
    public int CurvatureLevelCount { get; set; }

    /// <summary>终点位置允许的欧氏距离误差，单位 m。</summary>
    public double GoalPositionToleranceMeters { get; set; }

    /// <summary>终点车头航向允许的最小环形角度误差，单位 rad。</summary>
    public double GoalHeadingToleranceRadians { get; set; }

    /// <summary>单次搜索允许扩展的最大节点数。</summary>
    public int MaximumExpandedNodes { get; set; }

    /// <summary>单次搜索允许消耗的最长时间；超出后返回 <see cref="PlanningStatus.SearchTimeout"/>。</summary>
    public TimeSpan SearchTimeout { get; set; }

    /// <summary>二维绕障启发式的权重；1 表示不额外放大。</summary>
    public double HeuristicWeight { get; set; }

    /// <summary>倒车原语长度代价相对前进原语的倍率。</summary>
    public double ReverseCostMultiplier { get; set; }

    /// <summary>相邻原语发生换向时增加的等效距离代价，单位 m。</summary>
    public double GearSwitchPenaltyMeters { get; set; }

    /// <summary>曲率绝对值对应的无量纲代价权重。</summary>
    public double CurvatureMagnitudeWeight { get; set; }

    /// <summary>相邻曲率等级每变化一级增加的等效距离代价，单位 m。</summary>
    public double CurvatureChangePenaltyMetersPerLevel { get; set; }

    /// <summary>车体保守净空不足时增加的无量纲代价权重。</summary>
    public double ClearanceCostWeight { get; set; }

    /// <summary>计算净空代价时视为足够安全的车体保守净空，单位 m。</summary>
    public double ClearanceCostDistanceMeters { get; set; }

    /// <summary>是否允许生成倒车原语；false 时搜索只生成前进原语。</summary>
    public bool AllowReverse { get; set; }
}
