package rapanui.core;

import rapanui.dsl.moai.Formula;
import rapanui.dsl.moai.Rule;
import rapanui.dsl.moai.Term;

/**
 * Describes a transformation step from one term to another.
 *
 * This class is immutable.
 *
 */
public class Transformation {
	private final Term input;
	private final Term output;
	private final Rule rule;
	private final Formula[] premiseMatching;

	/**
	 * Creates a new transformation from the given parameters.
	 *
	 * @param input The original term which is transformed
	 * @param output The result of the transformation
	 * @param rule The underlying rule which allows the transformation
	 * @param premiseMatching Matches the rule's premises to known facts or premises of the environment
	 */
	Transformation(Term input, Term output, Rule rule, Formula[] premiseMatching) {
		// TODO: validate parameters? Or rely on valid input?

		assert input != null;
		assert output != null;
		assert rule != null;
		assert premiseMatching != null;

		this.input = input;
		this.output = output;
		this.rule = rule;
		this.premiseMatching = premiseMatching;
	}

	public Term getInput() {
		return input;
	}

	public Term getOutput() {
		return output;
	}

	public Rule getRule() {
		return rule;
	}

	public Formula[] getPremiseMatching() {
		return premiseMatching;
	}
}

@@ -324,16 +324,56 @@
 e rule;%0A
+%09private final int ruleConclusionIndex;%0A
 %09private
@@ -406,16 +406,16 @@
 tching;%0A
-
 %0A%09/**%0A%09 
@@ -643,32 +643,109 @@
  transformation%0A
+%09 * @param int The index of the used conclusion among the rule's conclusions%0A
 %09 * @param premi
@@ -885,16 +885,41 @@
 le rule,
+ int ruleConclusionIndex,
  Formula
@@ -1061,32 +1061,121 @@
 t rule != null;%0A
+%09%09assert 0 %3C= ruleConclusionIndex && ruleConclusionIndex %3C rule.getConclusions().size();%0A
 %09%09assert premise
@@ -1259,16 +1259,66 @@
 = rule;%0A
+%09%09this.ruleConclusionIndex = ruleConclusionIndex;%0A
 %09%09this.p
@@ -1470,24 +1470,24 @@
 getRule() %7B%0A
-
 %09%09return rul
@@ -1489,24 +1489,97 @@
 n rule;%0A%09%7D%0A%0A
+%09public int getRuleConclusionIndex() %7B%0A%09%09return ruleConclusionIndex;%0A%09%7D%0A%0A
 %09public Form

add ruleConclusionIndex for rules with multiple conclusions