package net.woodyfolsom.msproj.sgf;

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

public class SGFProperty {
	private SGFIdentifier identifier;
	private List<SGFValue<?>> values = new ArrayList<SGFValue<?>>();
	
	public void addValue(SGFValue<?> value) {
		this.values.add(value);
	}

	public SGFIdentifier getIdentifier() {
		return identifier;
	}
	
	public List<SGFValue<?>> getValues() {
		return Collections.unmodifiableList(values);
	}
	
	public void setIdentifier(SGFIdentifier ident) {
		this.identifier = ident;
	}
	
	public String toSGF() {
		if (values.size() == 0) {
			return identifier + "[]";
		}
		
		String sgfFormatString = identifier + "[" + values.get(0) + "]";
		for (int i = 1; i < values.size(); i++) {
			sgfFormatString += "[" + values.get(i) + "]";
		}
		
		return sgfFormatString;
	}
	
	@Override
	public String toString() {
		StringBuilder stringBuilder = new StringBuilder(identifier.toString());
		for (SGFValue<?> value : values) {
			stringBuilder.append("[");
			stringBuilder.append(value.toString());
			stringBuilder.append("]");
		}
		return stringBuilder.toString();
	}
}
