using System;

namespace MultiWheelC.TrajectoryPlanning.EMPlanner;

public sealed class EmPlanningResult
{
    public EmPlanningResult(EmPlanningStatus status, EmTrajectory trajectory, string failureReason)
    {
        if (!Enum.IsDefined(typeof(EmPlanningStatus), status))
            throw new ArgumentOutOfRangeException(nameof(status));

        bool isSuccess = status == EmPlanningStatus.Success || status == EmPlanningStatus.SuccessWithFallback;
        if (isSuccess && trajectory == null)
            throw new ArgumentException("Successful results require a trajectory.", nameof(trajectory));
        if (!isSuccess && trajectory != null)
            throw new ArgumentException("Only successful results may contain a trajectory.", nameof(trajectory));

        Status = status;
        Trajectory = trajectory;
        FailureReason = failureReason ?? string.Empty;
    }

    public EmPlanningStatus Status { get; }

    public EmTrajectory Trajectory { get; }

    public string FailureReason { get; }
}
