package leigh.mecha.nodegraph;

import leigh.eo.EO;
import leigh.eo.EOLoop;

import java.io.Serializable;

public class RemoteAttribute implements Attribute {
    private final Node remoteNode;
    private final String remoteAttribute;

    public RemoteAttribute(Node remoteNode, String remoteAttribute) {
        this.remoteNode = remoteNode;
        this.remoteAttribute = remoteAttribute;
    }

    public Node getRemoteNode() {
        return remoteNode;
    }

    @Override
    public Serializable getSingleValue(ProcessorState state) throws Exception {
        return remoteNode.getOutputSingle(remoteAttribute, state);
    }

    @Override
    public EO getObjectValue(ProcessorState state) throws Exception {
        return remoteNode.getOutputObject(remoteAttribute, state);
    }

    @Override
    public EOLoop getObjectsValue(ProcessorState state) throws Exception {
        return remoteNode.getOutputObjects(remoteAttribute, state);
    }

    @Override
    public String toString() {
        return "RemoteAttribute{" +
                "remoteAttribute='" + remoteAttribute + '\'' +
                '}';
    }
}
