#ifndef DIRECTOR_H
#define DIRECTOR_H
#include "galaxy.h"
#include "session_common.h"

class Dispatch;
class MenuDispatch;
class InputDispatch;

class Director {
 public:
  /**
   * This dispatches client_input, server_line and server_prompt.
   *
   * Set chain.setNotify() to get a response when it is done.
   * activate() to begin the chain.
   *
   * The chain has to_client, to_server functions that dispatch to those
   * functions in Dispatch/Director/Session.
   */
  std::shared_ptr<Dispatch> chain;

  StringFunc to_client;
  StringFunc to_server;
  // void Session::post(notifyFunc nf)
  std::function<void(notifyFunc)> post;

  void client_input(const std::string &input);
  void server_line(const std::string &line, const std::string &raw_line);
  void server_prompt(const std::string &prompt, const std::string &raw_prompt);

  bool active;
  // not sure if I need these or not?
  std::string current_raw_prompt;
  std::string current_prompt;

  std::string old_prompt;
  std::string old_raw_prompt;

  void proxy_activate();
  void proxy_deactivate();

  char game;  // 0 = not in a game

  // not sure on these...  or how I want to use them.
  // maybe this is the place for these?!
  // IF these are public -- Session can access them.  :P
  bool show_client;
  bool talk_direct;

  // maybe these would work better?
  std::function<void(bool)> set_show_client;
  std::function<void(bool)> set_talk_direct;

  Director();
  ~Director();

  int count;

  int current_sector;
  Galaxy galaxy;
  std::string username;

 private:
  void build_menu(void);
  std::shared_ptr<Dispatch> main_menu;
  std::shared_ptr<Dispatch> cim;
  std::shared_ptr<Dispatch> config_input;
  std::shared_ptr<Dispatch> scripts_menu;
  std::shared_ptr<Dispatch> script;

  InputDispatch *init_config_input(void);
  MenuDispatch *init_scripts_menu(void);

  // notifications
  void have_input(void);
  void menu_choice(void);
  void cim_done(void);
  void scripts_done(void);

  void information(void);

  void config_edit(void);
  void config_have_input(void);
  std::string config_item;  // current item being edited

  StringFunc SL_parser;
  StringFunc SF_cimline, SF_sectorline, SF_portline, SF_warpline, SF_infoline,
      SF_densityline, SF_computer_portline, SF_planetline;

  void SL_cimline(const std::string &line);
  void SL_thiefline(const std::string &line);
  void SL_sectorline(const std::string &line);
  void SL_portline(const std::string &line);
  void SL_computer_portline(const std::string &line);
  void SL_warpline(const std::string &line);
  void SL_infoline(const std::string &line);
  void SL_densityline(const std::string &line);
  void SL_planetline(const std::string &line);

  int computer_port_sector;
  bool computer_port_done;
};

#include "dispatchers.h"

#endif