package lift;

/** Responsible for a single passenger. */
public class PassengerThread extends Thread {
  private LiftView view;
  private LiftMonitor monitor;

  public PassengerThread(LiftView v, LiftMonitor m) {
    view = v;
    monitor = m;
  }

  /** Drives a passenger through the lift phases */
  public void run() {
    while (true) {
      Passenger p = view.createPassenger();
      p.begin();

      // Walk towards the lift
      monitor.increaseWaitEntry(p.getStartFloor());
      monitor.enterLift(p.getStartFloor(), p.getDestinationFloor());
      p.enterLift();

      // Passenger is now inside the lift, now exit
      monitor.enterCompleted();
      monitor.exitLift(p.getDestinationFloor());
      p.exitLift();

      // Despawn
      monitor.exitCompleted();
      p.end();
    }
  }
}
