package lc.conflux.nodegraph;

import lc.eo.EO;
import lc.mecha.nodegraph.ProcessorState;

import java.io.Serializable;
import java.math.BigDecimal;

public class MinNode extends AggregateNode {
    public static final String TYPE = "min";

    BigDecimal value;

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

    @Override
    public void start(ProcessorState state) {
        value = null;
    }

    @Override
    public void processRow(EO row, String key, ProcessorState state) throws Exception {
        BigDecimal x = row.getValueBigDecimal(key);

        if (x != null) {
            if (value == null)
                value = x;
            else if (value.compareTo(x) > 0)
                value = x;
        }
    }

    @Override
    public Serializable finish(ProcessorState state) {
        return value;
    }
}
