using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace MultiWheelC.TrajectoryPlanning.EMPlanner;

/// <summary>Immutable lateral hard bounds for one already-selected topological corridor.</summary>
public sealed class StaticCorridor
{
    public StaticCorridor(IReadOnlyList<LateralInterval> stations)
    {
        if (stations == null || stations.Count == 0)
            throw new ArgumentException("A static corridor requires stations.", nameof(stations));

        var copy = new List<LateralInterval>(stations.Count);
        double previousS = double.NegativeInfinity;
        for (int index = 0; index < stations.Count; index++)
        {
            LateralInterval station = stations[index];
            if (station == null || station.ReferenceS < previousS)
                throw new ArgumentException("Static corridor stations must be non-null and sorted.", nameof(stations));
            copy.Add(station);
            previousS = station.ReferenceS;
        }
        Stations = new ReadOnlyCollection<LateralInterval>(copy);
    }

    public IReadOnlyList<LateralInterval> Stations { get; }
}
