#include <iostream>
#include <string>

#include "fsm/Gate.h"

using namespace std;

class GateContext : public Gate::Context {
public:
  virtual void error(const char* state_name, const char* event_name) {
    cout << "error state=" << state_name << " event=" << event_name << endl;
  }
  virtual void Alarm(Gate::FSM* fsm)     { cout << "金払え!!" << endl; }
  virtual void EnterLocked(Gate::FSM*)   { cout << "ゲートが閉まりました" << endl; }
  virtual void EnterUnlocked(Gate::FSM*) { cout << "ゲートが開きました" << endl; }
  virtual void ExitLocked(Gate::FSM*)    { cout << "閉じた状態を終わります" << endl; }
  virtual void ExitUnlocked(Gate::FSM*)  { cout << "開いた状態を終わります" << endl; }
  virtual void Lock(Gate::FSM*)          { cout << "ゲートを閉めます" << endl; }
  virtual void ThankYou(Gate::FSM*)      { cout << "ありがとうございます" << endl; }
  virtual void Unlock(Gate::FSM*)        { cout << "ゲートを開けます" << endl; }
};

int main() {
  GateContext context;
  Gate::FSM fsm;
  fsm.setContext(&context);

  while ( true ) {
    cout << fsm.getState()->getName() << endl;
    cout << "  enter an event :";
    string event_name;
    cin >> event_name;
    if ( event_name == "exit" ) break;
    else
    if ( event_name == "Coin" ) fsm.Coin();
    else
    if ( event_name == "Pass" ) fsm.Pass();
    else continue;

  }
  return 0;
}

