package v6.apps.zelvak;

import java.util.List;

abstract class FixedArgumentsParsingFunction implements ParsingFunction {

	private final int length;
	
	private final boolean requiresBody;
	
	public FixedArgumentsParsingFunction(int length, boolean requiresBody) {
		this.length = length;
		this.requiresBody = requiresBody;
	}
	
	public FixedArgumentsParsingFunction(int length) {
		this(length, false);
	}

	@Override
	public Command applyArguments(List<Object> arguments) throws WTFException {
		if(arguments.size() != length){
			throw new WTFException("Invalid argument count.");
		}
		return applyCheckedArguments(arguments);
	}

	protected abstract Command applyCheckedArguments(List<Object> arguments) throws WTFException;

	@Override
	public boolean requiresBody() {
		return requiresBody;
	}
	
}
