#include <iostream>
using namespace std;
enum class State { InWork, InPub, AtHome, InGym };
enum class Event { GoWork, GoPub, GoHome, AnotherBeer, GoGym };
void signout();
void lockDoor();
void hic();
void minesAPint();
State Transition(Event e);

int main(void)
{
	int x = 0;

	//models transitions:
	cout << "\nEnter a number between 0 and 4:\n";
	cout << "0 = GoWork event \n 1: = GoPub event\n ";
	cout << "2: = GoHome\n 3: = Anotherbeer\n 4: =Go to Gym\n 5:exit program\n";


	while (x != 5)
	{
		cin >> x;
		State currentState = Transition((Event)x);
		cout<< "STATE: " << int(currentState)  <<endl;
		cout << "\nEnter a number between 0 and 4:\n";
		cout << "0 = GoWork event \n 1: = GoPub event\n ";
		cout << "2: = GoHome\n 3: = Anotherbeer\n 4: =Go Gym\n 5:exit program\n";

	}

}

State Transition(Event e)
//deals with state transitions and actions
{
	static State s = State::AtHome;
	switch (s)
	{
	case State::AtHome:
		switch (e)
		{
		case Event::GoWork:
			s = State::InWork;
			lockDoor();
			break;
		}
		break;
	case State::InWork:
		switch (e)
		{
		case Event::GoPub:
			s = State::InPub;
			signout();
			break;
		case Event::GoGym:
			s = State::InGym;
			signout();
			break;
		case Event::GoHome:
			s = State::AtHome;
			signout();
			break;
		}
		break;
	case State::InPub:
		switch (e)
		{
		case Event::GoHome:
			s = State::AtHome;
			hic();
			break;
		case  Event::AnotherBeer:
			minesAPint();
			break;
		}
		break; 
	case State::InGym:
			switch (e)
			{
			case Event::GoHome:
				s = State::AtHome;
				signout();
				break;
			case  Event::GoPub:
				s = State::InPub;
				minesAPint();
				break;
			}
			break;

	}
	return s;
}
void minesAPint()
{
	cout << "Mines a pint!!\n";
}
void signout()
{
	cout << "Good night worker W101\n";
}
void hic()
{
	cout << "I'm off home! Hic!!\n";
}
void lockDoor()
{
	cout << "Click - doors locked - off to work!!\n";
}
