using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public sealed class HyperJump
{
    private readonly Queue<HyperJumpPhase> Phases = new Queue<HyperJumpPhase>();

    public bool HavePhases => Phases.Count > 0;

    public HyperJumpPhase MoveNext() {
        if (Phases.Count > 0)
            return Phases.Dequeue();
        return null;
    }

    public void AddJump(NavigationPoint from, NavigationPoint to, NavigationPoint[] eventPoints = null) {
        if (eventPoints == null || eventPoints.Length == 0)
        {
            Phases.Enqueue(new HyperJumpPhase(from, to));
        }
        else
        {
            Phases.Enqueue(new HyperJumpPhase(from, eventPoints.First()));
            for (int i = 0; i < eventPoints.Length - 1; i++)
            {
                Phases.Enqueue(new HyperJumpPhase(eventPoints[i], eventPoints[i + 1]));
            }
            Phases.Enqueue(new HyperJumpPhase(eventPoints.Last(), to));
        }
    }
}

public sealed class HyperJumpPhase
{
    public readonly NavigationPoint From;
    public readonly NavigationPoint To;

    public HyperJumpPhase(NavigationPoint from, NavigationPoint to)
    {
        From = from;
        To = to;
    }
}