Something like: Finite State Machine
Like a dedicated library that handles the code for state transitions.