package nloc;
import java.util.List;
import java.util.ArrayList;


public class SequenceTuple {
  
  private Droplet droplet;
  private int minPos, maxPos;
  private List<Channel> path;
  private Channel currentBifuraction;

  public SequenceTuple(Droplet droplet, List<Channel> path) {
    this.minPos = 0;
    this.maxPos = 0;
    this.droplet = droplet;
    this.path = path;
    this.currentBifuraction = null;
  }

  public SequenceTuple(Droplet droplet, List<Channel> path, 
      Channel currentBifuraction) {
    this.minPos = 0;
    this.maxPos = 0;
    this.droplet = droplet;
    this.path = path;
    this.currentBifuraction = currentBifuraction;
  }

  public SequenceTuple(Droplet droplet, List<Channel> path, int minPos, int maxPos) {
    this.minPos = minPos;
    this.maxPos = maxPos;
    this.droplet = droplet;
    this.path = path;
    this.currentBifuraction = null;
  }

  public SequenceTuple(SequenceTuple stup) {
    this.minPos = stup.getMinPos();
    this.maxPos = stup.getMaxPos();
    this.droplet = stup.getDroplet();
    this.path = stup.getPath();
    this.currentBifuraction = stup.getCurrentBifurcation();
  }

  public int getMinPos() {
    return minPos;
  }

  public int getMaxPos() {
    return maxPos;
  }

  public Droplet getDroplet() {
    return droplet;
  }

  public List<Channel> getPath() {
    return path;
  }

  public void setMinPos(int minPos) {
    this.minPos = minPos;
  }

  public void setMaxPos(int maxPos) {
    this.maxPos = maxPos;
  }

  public void setDroplet(Droplet droplet) {
    this.droplet = droplet;
  }
  
  public void setPath(List<Channel> path) {
    this.path = path;
  }

  public void setCurrentBifurcation(Channel currentBifuraction) {
    this.currentBifuraction = currentBifuraction;
  }

  public Channel getCurrentBifurcation() {
    return currentBifuraction;
  }

  public Channel getPreviousBifurcation() {
    Channel prevBifurc = null;
    List<Channel> bfList = new ArrayList<Channel>();
    for (Channel ch: this.path) {
      if (ch instanceof Pump) {
        bfList.add(ch);
      }
      if (ch.isBifurcation()) {
        bfList.add(ch);
      }
    }
    if (this.currentBifuraction == null) {
      prevBifurc = bfList.get(bfList.size() - 1);
    } else if (!(this.currentBifuraction instanceof Pump)) {
      prevBifurc = bfList.get(bfList.indexOf(this.currentBifuraction) - 1);
    } else {
      prevBifurc = this.currentBifuraction;
    }
    return prevBifurc;
  }

  public Channel getPumpOutlet() {
    Channel outlet = null;
    for (Channel ch: path) {
      if (ch.getParents().size() == 1 && 
          ch.getParents().get(0) instanceof Pump) {
        outlet = ch;
      }
    }
    return outlet;
  }
}