package gov.va.escreening.dto.template;

import java.util.List;

public class TemplateFollowingConditionBlock{
	
	private String left;

	private String operator;

	private String right;

	private List<TemplateFollowingConditionBlock> conditions;

	public String getLeft() {
		return left;
	}

	public void setLeft(String left) {
		this.left = left;
	}

	public String getOperator() {
		return operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	public String getRight() {
		return right;
	}

	public void setRight(String right) {
		this.right = right;
	}

	public List<TemplateFollowingConditionBlock> getConditions() {
		return conditions;
	}

	public void setConditions(List<TemplateFollowingConditionBlock> conditions) {
		this.conditions = conditions;
	}

	
	private String connector;

	public String getConnector() {
		return connector;
	}

	public void setConnector(String connector) {
		this.connector = connector;
	}
	
	public String toFreeMarkerFormatFormula()
	{
		StringBuffer sb = new StringBuffer();
		sb.append(" ").append(connector).append(" (").append(FormulaUtil.createFormula(operator, left, right));
		
		if (conditions != null && conditions.size() > 0)
		{
			for(TemplateFollowingConditionBlock tfcb : conditions)
			{
				sb.append(tfcb.toFreeMarkerFormatFormula());
			}
		}
		
		sb.append(" ) ");
		return sb.toString();
	}
	
	

}

@@ -959,16 +959,156 @@
 r;%0A%09%7D%0A%09%0A
+%09private String getOperatorForConnector()%0A%09%7B%0A%09%09if (%22AND%22.equals(connector))%0A%09%09%7B%0A%09%09%09return %22 && %22;%0A%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09%09%09return %22 %7C%7C %22;%0A%09%09%7D%0A%09%7D%0A%09%0A
 %09public 
@@ -1209,25 +1209,39 @@
 .append(
-c
+getOperatorForC
 onnector
 ).append
@@ -1232,16 +1232,18 @@
 onnector
+()
 ).append

convert AND and OR to && ||.