#include "file_input.h"

#include <utility>
#include <string>
#include "constants.h"

file_input::file_input(std::ifstream &&ifs):
        in{std::move(ifs)} {}

game_command file_input::get_command() {
        std::string cmd;
        in >> cmd;

        if (in.eof())
                return GAME_COMMAND_TERMINATE;

        if (cmd == "q")
                return GAME_COMMAND_TERMINATE;
        else if (cmd == "f")
                return THE_WORLD;
        else if (cmd == "d")
                return STAR_PLATINUM;
        else if (cmd == "r")
                return GAME_RESTART;
        else if (cmd == "u" || cmd == "a" || cmd == "T") {
                auto cmdtmp = cmd;
                in >> cmd;

                if (in.eof())
                        return GAME_COMMAND_PANIC;

                auto tmp = get_direction(cmd);

                if (cmdtmp == "u")
                        return static_cast<game_command>
                               (tmp + APPLY_NORTH);
                else if (cmdtmp == "a")
                        return static_cast<game_command>
                               (tmp + ATTACK_NORTH);
                else
                        return static_cast<game_command>
                               (tmp + THROW_NORTH);
        } else if (cmd == "yes") {
                return game_command::ENTER;
        } else if (cmd == "i") {
                return TOGGLE_INVENTORY;
        } else if (cmd == "s") {
                return SELECT_SHADE;
        } else if (cmd == "d") {
                return SELECT_DROW;
        } else if (cmd == "v") {
                return SELECT_VAMPIRE;
        } else if (cmd == "g") {
                return SELECT_GOBLIN;
        } else if (cmd == "t") {
                return SELECT_TROLL;
        }  else {
                auto tmp = get_direction(cmd);

                if (tmp != GAME_COMMAND_PANIC)
                        return static_cast<game_command>
                               (tmp + MOVE_NORTH);
        }

        return GAME_COMMAND_PASS;
}
