/* ************************************************************************
#
#  DivConq
#
#  http://divconq.com/
#
#  Copyright:
#    Copyright 2012 eTimeline, LLC. All rights reserved.
#
#  License:
#    See the license.txt file in the project's top-level directory for details.
#
#  Authors:
#    * Andy White
#
************************************************************************ */
package divconq.script.mutator;

import divconq.script.Activity;
import divconq.script.IMutator;
import divconq.script.StackEntry;
import divconq.struct.ListStruct;
import divconq.struct.Struct;
import divconq.xml.XElement;

public class RemoveItemMutator implements IMutator {
	// only works on scalars

	@Override
	public void mutate(Activity activity, StackEntry stack, XElement code, Struct dest) {
		// resolve value only works with scalars
		if ((dest == null) || !(dest instanceof ListStruct)) {
			// TODO log
			return;
		}
		
		ListStruct dr = (ListStruct)dest;
		
		long idx = stack.intFromSource(code, "Index", -1); 
		
		if (idx > -1)
			dr.removeItem(idx);
	}
}
