package ws.prova;

import org.mandarax.kernel.Function;
import org.mandarax.kernel.Predicate;
import org.mandarax.kernel.SimplePredicate;
import org.mandarax.kernel.meta.JFunction;
import org.mandarax.kernel.meta.JPredicate;
import ws.prova.calc.CalcPredicate;
import ws.prova.kernel.PolyPredicate;

/*
 * Copyright (C) 2002-2007 <a href="mailto:a.kozlenkov@city.ac.uk">Alex Kozlenkov</a>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/**
 * Helper predicates as static methods used in reagent
 * <p>Title: Prova</p>
 * <p>Description: Helper predicates as static methods used in reagent</p>
 * <p>Copyright: Copyright (C) 2002-2007</p>
 * <p>Company: City University, London, United Kingdom </p>
 * Prova complete re-write
 *
 * @author <A HREF="mailto:a.kozlenkov@city.ac.uk">Alex Kozlenkov</A>
 * @version 2.0 <25 March 2007>
 */
public class HelperPredicates {
//	public HelperPredicates() {
//	}

	public static SimplePredicate state() {
		Class[] struct = {RList.class};
		SimplePredicate p = new SimplePredicate("state", struct);
		return p;
	}

	public static SimplePredicate solve_first() {
		Class[] struct = {
			RList.class};
		SimplePredicate p = new SimplePredicate("solve_first", struct);
		return p;
	}

	public static SimplePredicate solve() {
		Class[] struct = {
			RList.class};
		SimplePredicate p = new SimplePredicate("solve", struct);
		return p;
	}

	public static SimplePredicate eval() {
		Class[] struct = {
			RList.class};
		SimplePredicate p = new SimplePredicate("eval", struct);
		return p;
	}

	public static SimplePredicate consult() {
		Class[] struct = {
			RList.class};
		SimplePredicate p = new SimplePredicate("consult", struct);
		return p;
	}

	public static SimplePredicate temporal_rule() {
		Class[] struct = {
			Object.class, Object.class, RList.class};
		SimplePredicate p = new SimplePredicate("temporal_rule", struct);
		return p;
	}

	public static SimplePredicate temporal_rule_eoc() {
		Class[] struct = {
			Object.class, Object.class, RList.class};
		SimplePredicate p = new SimplePredicate("temporal_rule_eoc", struct);
		return p;
	}

	public static SimplePredicate temporal_rule_remove() {
		Class[] struct = {
				RList.class};
		SimplePredicate p = new SimplePredicate("temporal_rule_remove", struct);
		return p;
	}

	public static SimplePredicate conv_id() {
		Class[] struct = {
			Object.class, RList.class, RList.class};
		SimplePredicate p = new SimplePredicate("conv_id", struct);
		return p;
	}

	public static SimplePredicate actions() {
		Class[] struct = {
			Object.class, RList.class, Object.class, RList.class, RList.class};
		SimplePredicate p = new SimplePredicate("actions", struct);
		return p;
	}

	public static SimplePredicate actions2() {
		Class[] struct = {
			RList.class, Object.class, RList.class, RList.class};
		SimplePredicate p = new SimplePredicate("actions2", struct);
		return p;
	}

	public static SimplePredicate holds() {
		Class[] struct = {
			RList.class};
		SimplePredicate p = new SimplePredicate("holds", struct);
		return p;
	}

	public static SimplePredicate demo() {
		Class[] struct = {
			RList.class};
		SimplePredicate p = new SimplePredicate("demo", struct);
		return p;
	}

	public static SimplePredicate adapt() {
		Class[] struct = {
			RList.class, RList.class};
		SimplePredicate p = new SimplePredicate("adapt", struct);
		return p;
	}

	public static Predicate invoke() {
		try {
			Class[] par = {
				RList.class};
			return new JPredicate(Calc.class.getMethod("invoke", par));
		} catch (NoSuchMethodException x) {
			x.printStackTrace(System.err);
		}
		return null;
	}

	public static SimplePredicate fail() {
		Class[] struct = {};
		SimplePredicate p = new SimplePredicate("fail", struct);
		return p;
	}

	public static SimplePredicate restore_exhandler() {
		Class[] struct = {ws.prova.reference.ExceptionHandler.class};
		SimplePredicate p = new SimplePredicate("restore_exhandler", struct);
		return p;
	}

	public static SimplePredicate diff() {
		Class[] struct = {
			RList.class, RList.class, RList.class};
		SimplePredicate p = new SimplePredicate("diff", struct);
		return p;
	}

	public static SimplePredicate temporal_rule_build() {
		Class[] struct = {
			RList.class, RList.class, RList.class};
		SimplePredicate p = new SimplePredicate("temporal_rule_build", struct);
		return p;
	}

	public static SimplePredicate append() {
		Class[] struct = {
			RList.class, RList.class, RList.class};
		SimplePredicate p = new SimplePredicate("append", struct);
		return p;
	}

	public static SimplePredicate accumulate() {
		Class[] struct = {
			RList.class};
		SimplePredicate p = new SimplePredicate("accumulate", struct);
		//reagent.poly_predicates.put(p.getName(), p);
		return p;
	}

	public static SimplePredicate accumulate2() {
		Class[] struct = {
			RList.class};
		SimplePredicate p = new SimplePredicate("accumulate2", struct);
		return p;
	}

	public static SimplePredicate acc() {
		Class[] struct = {
			RList.class};
		SimplePredicate p = new SimplePredicate("acc", struct);
		//reagent.poly_predicates.put(p.getName(), p);
		return p;
	}

	public static SimplePredicate acc2() {
		Class[] struct = {
			RList.class};
		SimplePredicate p = new SimplePredicate("acc2", struct);
		return p;
	}

	public static SimplePredicate conversation() {
		Class[] struct = {
			Object.class, RList.class, RList.class, RList.class, RList.class};
		PolyPredicate p = new PolyPredicate("conversation", struct);
		return p;
	}

	/**
	 * Create a PolyPrediate representing the base predicate for dynamic
	 * predicates
	 *
	 * @return PolyPredicate
	 */
	public static PolyPredicate derive() {
		Class[] struct = {
			Object.class, RList.class};
		PolyPredicate p = new PolyPredicate("derive", struct);
		return p;
	}

	public static SimplePredicate derivation() {
		Class[] struct = {
			Object.class, RList.class, RList.class, RList.class};
		PolyPredicate p = new PolyPredicate("derivation", struct);
		return p;
	}

	public static Function list() {
		try {
			Class[] par = {
				Object.class};
			return new JFunction(RList.class.getMethod("list", par));
		} catch (NoSuchMethodException x) {
			x.printStackTrace(System.err);
		}
		return null;
	}

	public static CalcPredicate scalc() {
//		CalcClauseSet cs = new CalcClauseSet();
		CalcPredicate p = new CalcPredicate();

		p.setName("scalc");
		Class[] struct = {
			RList.class};
		p.setStructure(struct);

		return p;
	}

	public static ws.prova.calc.CalcPredicate fcalc() {
		CalcPredicate p = new CalcPredicate();

		p.setName("fcalc");
		Class[] struct = {
			RList.class};
		p.setStructure(struct);

		return p;
	}

	public static CalcPredicate sfcalc() {
		CalcPredicate p = new CalcPredicate();

		p.setName("sfcalc");
		Class[] struct = {
			RList.class};
		p.setStructure(struct);

		return p;
	}

//	private static Predicate invoke2() {
//		try {
//			Class[] par = {
//				RList.class};
//			return new JPredicate(
//				Calc.class.getMethod("invoke2", par));
//		}
//		catch (NoSuchMethodException x) {
//			x.printStackTrace(System.err);
//		}
//		return null;
//	}

//	static Predicate sendMsg() {
//		try {
//			Class[] par = {
//				RList.class};
//			return new JPredicate(
//				reagent.class.getMethod("sendMsg", par));
//		}
//		catch (NoSuchMethodException x) {
//			x.printStackTrace(System.err);
//		}
//		return null;
//	}

}
