package org.magicnexus.classes.ui.cli.parser;

import java.text.ParseException;

import org.magicnexus.classes.ui.cli.MagicNexusCliApplication;
import org.magicnexus.classes.ui.cli.command.AddPlayerCommand;
import org.magicnexus.classes.ui.cli.command.BackToMainCommand;
import org.magicnexus.classes.ui.cli.command.ExitCommand;
import org.magicnexus.classes.ui.cli.command.NoOpCommand;
import org.magicnexus.classes.ui.cli.menu.item.AddPlayerMenuItem;
import org.magicnexus.classes.ui.cli.menu.item.BackMenuItem;
import org.magicnexus.classes.ui.cli.menu.item.ExitMenuItem;
import org.magicnexus.interfaces.ui.cli.IParser;
import org.magicnexus.interfaces.ui.cli.IUiCommand;


public class PlayGameSetupParser implements IParser
{
	
	MagicNexusCliApplication application = null;
	
	public PlayGameSetupParser(MagicNexusCliApplication application)
	{
		this.application = application;
	}
	
	@Override
	public IUiCommand parseCommand(String nl) throws ParseException
	{
		if(nl == null || nl.length() == 0)
			return new NoOpCommand();
		nl = nl.trim().toLowerCase();
		if((new ExitMenuItem()).getCommandName().equals(nl))
			return new ExitCommand();
		if((new BackMenuItem()).getCommandName().equals(nl))
			return new BackToMainCommand(application);
		
		if(nl.length() > 3 && (new AddPlayerMenuItem()).getCommandName().equals(nl.substring(0, 3)))
			return new AddPlayerCommand(application, nl);
		
		return new NoOpCommand();
	}
	
}
