package hu.swankey.ammo.common.methods;

import hu.swankey.ammo.common.progstruct2.Method;
import hu.swankey.ammo.common.yggdrasil.basics.Field;
import hu.swankey.ammo.common.yggdrasil.basics.YObject;
import hu.swankey.ammo.common.yggdrasil.script.AmmoScriptException;

import java.util.Map;

public class Assign extends Method {

    public static final String FUNCTION_NAME = "assign";
    public static final String KEY_TARGET = "target";
    public static final String KEY_SOURCE = "source";
    public static final Assign function = new Assign();

    private Assign() {
    	super(FUNCTION_NAME);
        
        addParameter(KEY_TARGET, Field.yclass(), null);
        addParameter(KEY_SOURCE, YObject.yclass(), null);
    }


    @Override
    public YObject run(Map<String, YObject> params, Map<String, YObject> env, YObject thisElement) throws AmmoScriptException {

    	Field target = (Field) params.get(KEY_TARGET); 
    		//(Field)compute(params, env, thisElement, KEY_TARGET);
    	Field source = (Field) params.get(KEY_SOURCE);
    		//compute(params, env, thisElement, KEY_SOURCE);
    	
    	target.setValue( source.getValue() );
    	
    	return target;
    }

    @Override
    protected void checkParams(Map<String, YObject> parameters) throws AmmoScriptException {    	
    	System.out.println("TODO: 'Assign' parameter check.");
    }

}
