package com.forsvarir.mud;

import com.forsvarir.mud.commands.MudCommand;
import com.forsvarir.mud.commands.UnknownCommand;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class CommandProcessor {
    private final SessionManager sessionManager;
    private final CommandTokenizer commandTokenizer;
    private final UnknownCommand unknownCommand;
    private final Map<String, MudCommand> commands;

    public CommandProcessor(SessionManager sessionManager,
                            CommandTokenizer commandTokenizer,
                            UnknownCommand unknownCommand,
                            Map<String, MudCommand> commands) {
        this.sessionManager = sessionManager;
        this.commandTokenizer = commandTokenizer;
        this.unknownCommand = unknownCommand;
        this.commands = commands;
    }

    public void processCommand(String command, String principalName, String sessionId) {
        var tokens = commandTokenizer.extractTokens(command);
        var commandProcessor = commands.getOrDefault(tokens.getCommand() + "Command", unknownCommand);
        var sender = sessionManager.findPlayer(principalName, sessionId);
        commandProcessor.processCommand(tokens.getArguments(), sender);
    }
}

@@ -1065,16 +1065,41 @@
 Default(
+calculateCommandBeanName(
 tokens.g
@@ -1113,21 +1113,26 @@
 nd()
- + %22Command%22,
+),%0A               
  unk
@@ -1296,11 +1296,116 @@
 );%0A    %7D
+%0A%0A    private String calculateCommandBeanName(String command) %7B%0A        return command + %22Command%22;%0A    %7D
 %0A%7D%0A

Make it explicit where command class name comes from