package leigh.conflux.nodegraph;

import leigh.eo.EO;
import leigh.mecha.nodegraph.Node;
import leigh.mecha.nodegraph.ProcessorState;
import leigh.mecha.util.Snavig;

import java.io.Serializable;

public class UpdateNode extends Node {
    public static final String KEY_INPUT_OBJ = "obj";
    public static final String KEY_INPUT_KEY = "key";
    public static final String KEY_INPUT_VALUE = "value";

    public UpdateNode(String id) {
        super(id);
    }

    /**
     * Perform the update operation by reading a key/value pair from upstream and writing that into the provided
     * object.
     */
    public void process(ProcessorState state) throws Exception {
        EO input = getInputObject(KEY_INPUT_OBJ, state);
        String key = Snavig.convertToString(getInputSingle(KEY_INPUT_KEY, state));
        Serializable value = getInputSingle(KEY_INPUT_VALUE, state);

        input.setValue(key, value);
    }
}
