package command;

import cli.CommandLineInterface;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;

public class CommandSelector {

    private CommandLineInterface commandLineInterface;
    private String[] enteredCommand;

    public CommandSelector(String[] enteredCommand) {
        this.enteredCommand = enteredCommand;
        this.commandLineInterface = new CommandLineInterface();

    }

    public void executeCommand() {
        try {
            CommandLine userInput = commandLineInterface.getInput(enteredCommand);
            Command command;
            if (userInput.hasOption("new")) {
                command = createIssue(userInput.getOptionValues("new"));
            } else if (userInput.hasOption("init")) {
                command = init();
            } else {
                command = nullCommand();
            }
            command.execute();

        } catch (ParseException e) {
            e.printStackTrace(); //todo
        }
    }

    private Command init() {
        return new CommandInit();
    }

    private Command nullCommand() {
        return new CommandNull();
    }

    private Command createIssue(String[] args) {
        return new CommandCreate(args);
    }

    private Command pushIssue() {
        return new CommandPush();
    }
}