/*
 * Created on Aug 18, 2008 (C) Copyright TANDBERG Television Ltd.
 */

package com.tandbergtv.watchpoint.pmm.util.validation;

import java.util.ArrayList;
import java.util.List;

/**
 * A Validation Message that contains an appropriate code and a list of properties associated with
 * the message.
 * 
 * @author Vijay Silva
 */
public class ValidationMessage {

	/* The validation message code */
	private String code;

	/* The validation message properties */
	private List<String> properties = new ArrayList<String>();

	/**
	 * Constructor
	 * 
	 * @param messageCode The validation message code
	 */
	public ValidationMessage(String messageCode) {
		this(messageCode, null);
	}

	/**
	 * Constructor
	 * 
	 * @param messageCode The validation message code
	 * @param messageProperties The list of validation message properties
	 */
	public ValidationMessage(String messageCode, List<String> messageProperties) {
		this.code = messageCode;
		if (messageProperties != null) {
			this.properties.addAll(messageProperties);
		}
	}

	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}

	/**
	 * @return the properties
	 */
	public List<String> getProperties() {
		return properties;
	}

	/**
	 * Gets the property at the specified index, or null if the index is invalid
	 * 
	 * @param index (0 based) index of the property in the list
	 * @return The property value, or null if no such property exists
	 */
	public String getProperty(int index) {
		return (index >= 0 && index < this.properties.size()) ? this.properties.get(index) : null;
	}

	/**
	 * Displays the validation message code and properties
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("ValidationMessage[");
		builder.append(this.code);
		builder.append(" : ");
		builder.append(this.properties.toString());
		builder.append("]");

		return builder.toString();
	}
}
