package com.tandbergtv.metadatamanager.validation;

import java.util.List;
import java.util.Locale;

/**
 * This class contains the error code and the location of the erroneous field.
 * It also provides a method to get the error message for the errorCode based in
 * the provided language.
 * 
 * @author spuranik
 * 
 */
public class ValidationError {

	/* error code */
	private String errorCode;

	/* location in document which generated the error code */
	private String errorLocation;

	/* error fields used to build the resource string */
	private List<String> errorFields;

	/* info used to build the resource string */
	private List<String> errorInfo;

	/**
	 * @return the errorInfo
	 */
	public List<String> getErrorInfo() {
		return errorInfo;
	}

	/**
	 * @param errorInfo
	 *            the errorInfo to set
	 */
	public void setErrorInfo(List<String> errorInfo) {
		this.errorInfo = errorInfo;
	}

	/**
	 * @return the errorFields
	 */
	public List<String> getErrorFields() {
		return errorFields;
	}

	/**
	 * @param errorFields
	 *            the errorFields to set
	 */
	public void setErrorFields(List<String> errorFields) {
		this.errorFields = errorFields;
	}

	/**
	 * @return the errorCode
	 */
	public String getErrorCode() {
		return errorCode;
	}

	/**
	 * @return the errorLocation
	 */
	public String getErrorLocation() {
		return errorLocation;
	}

	public ValidationError(String errorCode, String location,
			List<String> fields, List<String> info) {
		this.errorCode = errorCode.trim();
		this.errorLocation = location.trim();
		this.errorFields = fields;
		this.errorInfo = info;
	}

	/**
	 * Gets the message for the error code in the given locale.
	 * 
	 * @param errorCode
	 * @param locale
	 */
	public String getMessage(Locale locale) {
		return ErrorCodeLookup.lookup(this, locale);
	}

	public String toString() {
		return getErrorCode() + "-" + getErrorLocation() + "/" + getErrorFields() + " message= " + getMessage(new Locale("en", "US"));
	}
}
