package Server.Automaton;

public enum GameState implements Comparable<GameState> {
    UNKNOWN,
    SETUP,
    NEXT_ROUND,
    TOTEM_PLACEMENT,
    ACTION_RESOLUTION,
    END_ACTION,
    EXTRA_DRAW,
    EVENT_RESOLUTION,
    GAME_OVER;

    GameState next(int turn){
        switch (this) {
            case SETUP:
                return SETUP;
            case NEXT_ROUND:
                return NEXT_ROUND;
            case TOTEM_PLACEMENT:
                return ACTION_RESOLUTION;
            case ACTION_RESOLUTION:
                return END_ACTION;
            case EXTRA_DRAW:
                return EXTRA_DRAW;
            case END_ACTION:
                if(turn != 10) return GAME_OVER;
                return TOTEM_PLACEMENT;
            default: return UNKNOWN;
        }
    }

    static GameState fromString(String s){
        return switch (s.toUpperCase().charAt(0)) {
            case 'S' -> SETUP;
            case 'T' -> TOTEM_PLACEMENT;
            case 'A' -> ACTION_RESOLUTION;
            case 'E' -> END_ACTION;
            case 'X' -> EXTRA_DRAW;
            case 'G' -> GAME_OVER;
            case 'N' -> NEXT_ROUND;
            default -> UNKNOWN;
        };
    }

    @Override
    public String toString() {
        switch (this) {
            case SETUP:
                return "SETUP";
            case TOTEM_PLACEMENT:
                return "TOTEM_PLACEMENT";
            case ACTION_RESOLUTION:
                return "ACTION_RESOLUTION";
            case END_ACTION:
                return "END_ACTION";
            case EVENT_RESOLUTION:
                return "EVENT_RESOLUTION";
            case NEXT_ROUND:
                return "NEXT_ROUND";
            case EXTRA_DRAW:
                return "EXTRA_DRAW";
            case GAME_OVER:
                return "GAME_OVER";
            default: return "UNKNOWN";
        }
    }
}
