#ifndef STATEHANDLER_H
#define STATEHANDLER_H

#include <libxml/parser.h>

#include <stdint.h>
#include <vector>
#include <string>
using namespace std;

#include "../util/Param.h"

#include "../interface/LocalInputCollection.h"

#include "../graphics/shippingHandler.h"
#include "../graphics/Renderer.h"

#include "../ruleset/Rules.h"

//definitions of states are found in
#include "StateDefines.h"

class Session;

//StateHandler takes care of the states and various flow of the game.
class StateHandler {
 public:
  StateHandler ();
  ~StateHandler ();

  bool initialize ();
  void quit();

  void gatherInput ();

  void go();

  bool getWantsToQuit();
  bool checkForQuitInput();

  //State control: The methods used to select state routines
  void dispatchState(int targetState, int partOfState);

  //session
  void setSession (Session *);
  Session * getSession ();

  //comparing inputs to hitBoxes
  void applyInputToHitBoxes (int inputToLookFor);
  void applyInputToHitBoxes (int inputToLookFor, vector <HitBox*> &);

  //debugging
  void debugTest(int);

 private:
  //state-specific functions

  //Player Attacks phase
  void stateDebugPlayerAttacks ();
  void stateStartPlayerAttacks ();
  void stateBeforeDrawPlayerAttacks ();
  void stateApplyInputPlayerAttacks ();
  void stateEndPlayerAttacks ();

  //Round switching phase
  void stateDebugBattleSwitchRound ();
  void stateStartBattleSwitchRound ();
  void stateBeforeDrawBattleSwitchRound ();
  void stateApplyInputBattleSwitchRound ();
  void stateEndBattleSwitchRound ();

  //Feature Testing phase
  void stateDebugTest ();
  void stateStartTest ();
  void stateBeforeDrawTest ();
  void stateApplyInputTest ();
  void stateEndTest ();

  //Attack Preview shows the attack the player wants to use.
  void stateDebugAttackPreview ();
  void stateStartAttackPreview ();
  void stateBeforeDrawAttackPreview ();
  void stateApplyInputAttackPreview ();
  void stateEndAttackPreview ();

  //Attack Drawing, the player draws lines
  void stateDebugAttackDrawing ();
  void stateStartAttackDrawing ();
  void stateBeforeDrawAttackDrawing ();
  void stateApplyInputAttackDrawing ();
  void stateEndAttackDrawing ();

  void stateAttackDrawingHelper1(int);
  bool stateAttackDrawingHelper2(FixedInt & corigx, FixedInt & corigy, AffineTransformationMatrix & atm, int radius, int ax, int ay, int bx, int by, int abQuad);

  //Attack Finished, calculate and show results
  void stateDebugAttackFinished ();
  void stateStartAttackFinished ();
  void stateBeforeDrawAttackFinished ();
  void stateApplyInputAttackFinished ();
  void stateEndAttackFinished ();

  //Attack Wait For User, user missed, waiting for user to click again
  void stateDebugAttackWaitForUser ();
  void stateStartAttackWaitForUser ();
  void stateBeforeDrawAttackWaitForUser ();
  void stateApplyInputAttackWaitForUser ();
  void stateEndAttackWaitForUser ();

  //Defend Clicking: Paths are drawn, user clicks on them to halt them.
  void stateDebugDefendClicking ();
  void stateStartDefendClicking ();
  void stateBeforeDrawDefendClicking ();
  void stateApplyInputDefendClicking ();
  void stateEndDefendClicking ();

  Session * session;
};
#endif
