@startuml
title Elevator
state "active" as active {
  state "floorListener" as floorListener {
    state "floorSelecting" as floorSelecting {
    }
    [*] -right-> floorSelecting
  }
  --
  state "movingElevator" as movingElevator {
    state "moving" as moving {
      state "movingDown" as movingDown {
        movingDown : **entry** / current = current - 1
      }
      state "movingUp" as movingUp {
        movingUp : **entry** / current = current + 1
      }
    }
    state "doorsClosed" as doorsClosed {
    }
    state "doorsOpen" as doorsOpen {
    }
    [*] -right-> doorsOpen
  }
}
floorSelecting --> floorSelecting : floorSelected / destination = event.floor
movingDown --> movingDown : [destination < current]
movingUp --> movingUp : [destination > current]
moving --> doorsOpen : [destination == current] / doors_open = True
doorsClosed --> movingUp : [destination > current]
doorsClosed --> movingDown : [destination < current and destination >= 0]
doorsOpen -right-> doorsClosed : [destination != current] / doors_open = False
doorsOpen -right-> doorsClosed : [after(10) and current > 0] / destination = 0; doors_open = False
@enduml
