using System;

namespace MultiWheelC.TrajectoryPlanning.EMPlanner;

/// <summary>Result of the lateral stage; only independently validated paths may be successful.</summary>
public sealed class LateralPlanningResult
{
    public LateralPlanningResult(EmPlanningStatus status, LateralPath path, string failureReason)
    {
        if (!Enum.IsDefined(typeof(EmPlanningStatus), status))
            throw new ArgumentOutOfRangeException(nameof(status));

        bool successful = status == EmPlanningStatus.Success || status == EmPlanningStatus.SuccessWithFallback;
        if (successful && (path == null || path.Points.Count == 0 || !path.IsIndependentlyValidated))
            throw new ArgumentException("Successful lateral results require a non-empty independently validated path.", nameof(path));
        if (!successful && path != null)
            throw new ArgumentException("Failed lateral results cannot contain a path.", nameof(path));

        Status = status;
        Path = path;
        FailureReason = failureReason ?? string.Empty;
    }

    public EmPlanningStatus Status { get; }

    public LateralPath Path { get; }

    public string FailureReason { get; }
}
