package com.uas.report.axis;

import java.util.ArrayList;
import java.util.List;

public class Request {

	/**
	 * List of arguments
	 */
	private List<Argument> arguments = new ArrayList<>();
	private ResourceDescriptor resourceDescriptor;

	private String operationName = null;
	private String locale = null; // a string defining locale...

	public List<Argument> getArguments() {
		return arguments;
	}

	public void setArguments(List<Argument> arguments) {
		this.arguments = arguments;
	}

	public ResourceDescriptor getResourceDescriptor() {
		return resourceDescriptor;
	}

	public void setResourceDescriptor(ResourceDescriptor resourceDescriptor) {
		this.resourceDescriptor = resourceDescriptor;
	}

	public String getOperationName() {
		return operationName;
	}

	public void setOperationName(String operationName) {
		this.operationName = operationName;
	}

	public String getLocale() {
		return locale;
	}

	public void setLocale(String locale) {
		this.locale = locale;
	}

	public String getArgumentValue(String argumentName) {
		String value = null;
		for (int i = 0; i < arguments.size(); ++i) {
			Argument a = (Argument) arguments.get(i);
			if (a.getName() == null ? a.getName() == argumentName : a.getName().equals(argumentName)) {
				value = a.getValue();
				break;
			}
		}
		return value;
	}

	/**
	 * Determines if a specific argument name is present in this request's list
	 * of arguments.
	 * 
	 * @param argumentName
	 *            the name of the argument to look for
	 * @return <code>true</code> if an argument having the specified name is
	 *         found in this request
	 */
	public boolean hasArgument(String argumentName) {
		boolean found = false;
		for (int i = 0; i < arguments.size(); ++i) {
			Argument arg = (Argument) arguments.get(i);
			if (argumentName.equals(arg.getName())) {
				found = true;
				break;
			}
		}
		return found;
	}

	@Override
	public String toString() {
		return "Request [arguments=" + arguments + ", resourceDescriptor=" + resourceDescriptor + ", operationName="
				+ operationName + ", locale=" + locale + "]";
	}

}
