package mb.statix.scopegraph.terms.path;

import java.util.Iterator;

import org.immutables.serial.Serial;
import org.immutables.value.Value;

import com.google.common.collect.Iterators;

import io.usethesource.capsule.Set;
import mb.nabl2.util.collections.PSequence;
import mb.statix.scopegraph.path.IStep;

@Value.Immutable
@Serial.Version(value = 42L)
abstract class AStep<V, L> implements IStep<V, L> {

    @Value.Parameter @Override public abstract V getSource();

    @Value.Parameter @Override public abstract L getLabel();

    @Value.Parameter @Override public abstract V getTarget();

    @Value.Lazy @Override public int size() {
        return 1;
    }

    @Value.Lazy @Override public Set.Immutable<V> getScopes() {
        return Set.Immutable.of(getSource(), getTarget());
    }

    @Value.Lazy @Override public PSequence<L> getLabels() {
        return PSequence.of(getLabel());
    }

    @Override public Iterator<IStep<V, L>> iterator() {
        return Iterators.singletonIterator(this);
    }

    @Override public String toString(boolean includeTo, boolean includeFrom) {
        StringBuilder sb = new StringBuilder();
        if(includeFrom) {
            sb.append(getSource());
            sb.append(Paths.PATH_SEPARATOR);
        }
        sb.append(getLabel());
        if(includeTo) {
            sb.append(Paths.PATH_SEPARATOR);
            sb.append(getTarget());
        }
        return sb.toString();
    }

    @Override public String toString() {
        return toString(true, true);
    }

}
@@ -1063,18 +1063,22 @@
  include
-To
+Source
 , boolea
@@ -1082,28 +1082,30 @@
 lean include
-From
+Target
 ) %7B%0A        
@@ -1166,12 +1166,14 @@
 lude
-From
+Source
 ) %7B%0A
@@ -1313,17 +1313,21 @@
 includeT
-o
+arget
 ) %7B%0A    

Fix toString of steps.